-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search page for community #970
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
<template> | ||
<section class="header"> | ||
<CenteredWrapper class="header-content"> | ||
<h1 class="title"> | ||
<template v-if="titleForResult != null"> | ||
<!-- TODO: support vnode as i18n message to simplify such case --> | ||
{{ $t(titleForResult.prefix) }}<span class="keyword">{{ keyword }}</span | ||
>{{ $t(titleForResult.suffix) }} | ||
</template> | ||
<template v-else> | ||
{{ $t(titleForNoResult) }} | ||
</template> | ||
</h1> | ||
<label class="order"> | ||
{{ | ||
$t({ | ||
en: 'Sort by', | ||
zh: '排序方式' | ||
}) | ||
}} | ||
<UISelect v-model:value="order"> | ||
<UISelectOption :value="Order.RecentlyUpdated">{{ | ||
$t({ | ||
en: 'Recently Updated', | ||
zh: '最近更新' | ||
}) | ||
}}</UISelectOption> | ||
<UISelectOption :value="Order.MostlyLiked">{{ | ||
$t({ | ||
en: 'Mostly Liked', | ||
zh: '最受喜欢' | ||
}) | ||
}}</UISelectOption> | ||
<UISelectOption :value="Order.MostlyRemixed">{{ | ||
$t({ | ||
en: 'Mostly Remixed', | ||
zh: '改编最多' | ||
}) | ||
}}</UISelectOption> | ||
</UISelect> | ||
</label> | ||
</CenteredWrapper> | ||
</section> | ||
<CenteredWrapper class="main"> | ||
<UILoading v-if="isLoading" /> | ||
<UIError v-else-if="error != null" :retry="refetch"> | ||
{{ $t(error.userMessage) }} | ||
</UIError> | ||
<div v-else-if="result?.data.length === 0" class="empty"> | ||
<UIEmpty size="large" /> | ||
</div> | ||
<template v-else-if="result != null"> | ||
<ul class="projects"> | ||
<ProjectItem v-for="project in result.data" :key="project.id" :project="project" /> | ||
</ul> | ||
<footer v-show="pageTotal > 1" class="pagination-wrapper"> | ||
<UIPagination v-model:current="page" :total="pageTotal" /> | ||
</footer> | ||
</template> | ||
</CenteredWrapper> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { useRouteQuery } from '@/utils/route' | ||
import { useQuery } from '@/utils/exception' | ||
import { IsPublic, listProject, ownerAll, type ListProjectParams } from '@/apis/project' | ||
import { | ||
UIError, | ||
UILoading, | ||
UISelect, | ||
UISelectOption, | ||
UIPagination, | ||
UIEmpty | ||
} from '@/components/ui' | ||
import CenteredWrapper from '@/components/community/CenteredWrapper.vue' | ||
import ProjectItem from '@/components/project/item/ProjectItem.vue' | ||
|
||
const params = useRouteQuery<'q' | 'p' | 'o'>() | ||
|
||
const keyword = computed(() => params.get('q') ?? '') | ||
|
||
const pageSize = 8 // 2 rows | ||
const defaultPage = 1 | ||
const page = computed<number>({ | ||
get() { | ||
const pageStr = params.get('p') | ||
if (pageStr == null || pageStr === '') return defaultPage | ||
const page = parseInt(pageStr) | ||
return isNaN(page) ? defaultPage : page | ||
}, | ||
set(p) { | ||
params.set('p', p === defaultPage ? null : p.toString()) | ||
} | ||
}) | ||
|
||
enum Order { | ||
RecentlyUpdated = 'update', | ||
MostlyLiked = 'likes', | ||
MostlyRemixed = 'remix' | ||
} | ||
const defaultOrder = Order.RecentlyUpdated | ||
|
||
const order = computed<Order>({ | ||
get() { | ||
const orderStr = params.get('o') | ||
if (orderStr == null || orderStr === '') return defaultOrder | ||
if (!Object.values(Order).includes(orderStr as Order)) return defaultOrder | ||
return orderStr as Order | ||
}, | ||
set(o) { | ||
params.set({ | ||
o: o === defaultOrder ? null : o, | ||
p: null | ||
}) | ||
} | ||
}) | ||
|
||
const pageTotal = computed(() => Math.ceil((result.value?.total ?? 0) / pageSize)) | ||
|
||
const listParams = computed<ListProjectParams>(() => { | ||
const p: ListProjectParams = { | ||
isPublic: IsPublic.public, | ||
owner: ownerAll, | ||
pageSize, | ||
pageIndex: page.value | ||
} | ||
if (keyword.value !== '') p.keyword = keyword.value | ||
switch (order.value) { | ||
case Order.RecentlyUpdated: | ||
p.orderBy = 'uTime' | ||
p.sortOrder = 'desc' | ||
break | ||
case Order.MostlyLiked: | ||
p.orderBy = 'likeCount' | ||
p.sortOrder = 'desc' | ||
break | ||
case Order.MostlyRemixed: | ||
p.orderBy = 'remixCount' | ||
p.sortOrder = 'desc' | ||
break | ||
} | ||
return p | ||
}) | ||
|
||
const { | ||
data: result, | ||
isLoading, | ||
error, | ||
refetch | ||
} = useQuery(() => listProject(listParams.value), { | ||
en: 'Failed to search projects', | ||
zh: '搜索项目失败' | ||
}) | ||
|
||
const titleForResult = computed(() => { | ||
if (result.value == null) return null | ||
return { | ||
prefix: { | ||
en: `Found ${result.value?.total} projects for "`, | ||
zh: `找到 ${result.value?.total} 个关于“` | ||
}, | ||
suffix: { | ||
en: '"', | ||
zh: '”的项目' | ||
} | ||
} | ||
}) | ||
const titleForNoResult = computed(() => ({ | ||
en: 'Search projects', | ||
zh: '搜索项目' | ||
})) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.header { | ||
flex: 0 0 64px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: var(--ui-color-grey-100); | ||
} | ||
|
||
.header-content { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 20px; | ||
|
||
.title { | ||
color: var(--ui-color-title); | ||
font-size: 16px; | ||
line-height: 26px; | ||
|
||
.keyword { | ||
color: var(--ui-color-primary-main); | ||
} | ||
} | ||
} | ||
|
||
.main { | ||
flex: 1 1 0; | ||
padding: 20px 0; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
} | ||
|
||
.empty { | ||
flex: 1 1 0; | ||
display: flex; | ||
|
||
border-radius: var(--ui-border-radius-2); | ||
background: var(--ui-color-grey-100); | ||
} | ||
|
||
.projects { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-content: flex-start; | ||
gap: 20px; | ||
} | ||
|
||
.pagination-wrapper { | ||
flex: 0 0 56px; | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
border-radius: var(--ui-border-radius-2); | ||
border: 1px solid var(--ui-color-grey-400); | ||
background: var(--ui-color-grey-100); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不设置
owner
(也就是不根据owner
过滤项目),应该就是指包含所有用户的(公开)项目?是不是没必要再用*
表示所有There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前不指定
owner
(默认)是 list 当前用户的项目调整成不指定
owner
表示“所有用户”也是可以的,只是那样的话 list 当前用户的项目会比较麻烦,接口调用方需要总是先去读到当前用户 name 才能组装出请求参数There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照目前后端实现,不指定
owner
的意思应该是 list 所有用户的公开项目:builder/spx-backend/internal/controller/project.go
Lines 59 to 71 in 4882f5f
好像一直是这样实现的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
owner
的值在cmd/spx-backend/get_projects_list.yap
这里被转换过There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂好吧我忘了这里还会做处理,那我来改一下 api spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK