Skip to content

Commit

Permalink
disable remix for project with no releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Oct 25, 2024
1 parent 3168ee5 commit 3a2bcc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
45 changes: 10 additions & 35 deletions spx-gui/src/components/community/project/ReleaseHistory.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
<script setup lang="ts">
import { useQuery } from '@/utils/query'
import { type QueryRet } from '@/utils/query'
import { humanizeTime } from '@/utils/utils'
import { listReleases } from '@/apis/project-release'
import { type ProjectRelease } from '@/apis/project-release'
import { UITimeline, UITimelineItem, UILoading, UIError } from '@/components/ui'
const props = defineProps<{
owner: string
name: string
defineProps<{
queryRet: QueryRet<ProjectRelease[]>
}>()
const {
data: releases,
isLoading,
error,
refetch
} = useQuery(
async () => {
const { owner, name } = props
const { data } = await listReleases({
projectFullName: `${owner}/${name}`,
orderBy: 'createdAt',
sortOrder: 'desc',
pageIndex: 1,
pageSize: 10 // load at most 10 recent releases
})
return data
},
{ en: 'Load release history failed', zh: '加载发布历史失败' }
)
defineExpose({
refetch
})
</script>

<template>
<UILoading v-if="isLoading" />
<UIError v-else-if="error != null" :retry="refetch">
{{ $t(error.userMessage) }}
<UILoading v-if="queryRet.isLoading.value" />
<UIError v-else-if="queryRet.error.value != null" :retry="queryRet.refetch">
{{ $t(queryRet.error.value.userMessage) }}
</UIError>
<p v-else-if="releases?.length === 0">
<p v-else-if="queryRet.data.value?.length === 0">
{{ $t({ en: 'No release history yet', zh: '暂无发布历史' }) }}
</p>
<UITimeline v-else-if="releases != null">
<UITimeline v-else-if="queryRet.data.value != null">
<UITimelineItem
v-for="release in releases"
v-for="release in queryRet.data.value"
:key="release.id"
:time="$t(humanizeTime(release.createdAt))"
>
Expand Down
25 changes: 22 additions & 3 deletions spx-gui/src/pages/community/project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEnsureSignedIn } from '@/utils/user'
import { usePageTitle } from '@/utils/utils'
import { ownerAll, recordProjectView, stringifyRemixSource, Visibility } from '@/apis/project'
import { listProject } from '@/apis/project'
import { listReleases } from '@/apis/project-release'
import { Project } from '@/models/project'
import { useUser, useUserStore } from '@/stores/user'
import { getProjectEditorRoute, getUserPageRoute } from '@/router'
Expand Down Expand Up @@ -206,14 +207,31 @@ const handleRemix = useMessageHandle(
{ en: 'Failed to remix project', zh: '改编项目失败' }
)
const releaseHistoryRef = ref<InstanceType<typeof ReleaseHistory>>()
const releasesRet = useQuery(
async () => {
const { owner, name } = props
const { data } = await listReleases({
projectFullName: `${owner}/${name}`,
orderBy: 'createdAt',
sortOrder: 'desc',
pageIndex: 1,
pageSize: 10 // load at most 10 recent releases
})
return data
},
{ en: 'Load release history failed', zh: '加载发布历史失败' }
)
const hasRelease = computed(
() => releasesRet.data.value != null && releasesRet.data.value?.length > 0
)
const unpublishProject = useUnpublishProject()
const handleUnpublish = useMessageHandle(
async () => {
const p = await untilNotNull(project)
await unpublishProject(p)
releaseHistoryRef.value?.refetch()
releasesRet.refetch()
},
{ en: 'Failed to unpublish project', zh: '取消发布项目失败' },
{
Expand Down Expand Up @@ -389,6 +407,7 @@ const remixesRet = useQuery(
</template>
<template v-else>
<UIButton
v-if="hasRelease"
type="primary"
size="large"
icon="remix"
Expand Down Expand Up @@ -430,7 +449,7 @@ const remixesRet = useQuery(
:title="$t({ en: 'Release history', zh: '发布历史' })"
name="releases"
>
<ReleaseHistory ref="releaseHistoryRef" :owner="props.owner" :name="props.name" />
<ReleaseHistory :query-ret="releasesRet" />
</UICollapseItem>
</UICollapse>
</template>
Expand Down

0 comments on commit 3a2bcc2

Please sign in to comment.