diff --git a/spx-gui/src/apis/common/index.ts b/spx-gui/src/apis/common/index.ts index c6eaf2de5..55b684f16 100644 --- a/spx-gui/src/apis/common/index.ts +++ b/spx-gui/src/apis/common/index.ts @@ -33,4 +33,9 @@ export type FileCollection = { [path: string]: UniversalUrl } +/** Get time string for spx-backend APIs */ +export function timeStringify(time: number) { + return new Date(time).toISOString() +} + export const client = new Client() diff --git a/spx-gui/src/apis/project.ts b/spx-gui/src/apis/project.ts index 4f0e65a0f..b0361a4ba 100644 --- a/spx-gui/src/apis/project.ts +++ b/spx-gui/src/apis/project.ts @@ -1,5 +1,6 @@ +import dayjs from 'dayjs' import type { FileCollection, ByPage, PaginationParams } from './common' -import { client, IsPublic, ownerAll } from './common' +import { client, IsPublic, ownerAll, timeStringify } from './common' import { ApiException, ApiExceptionCode } from './common/exception' export { IsPublic, ownerAll } @@ -105,6 +106,14 @@ export type ListProjectParams = PaginationParams & { owner?: string /** Filter projects by name pattern */ keyword?: string + /** Filter projects that were created after this timestamp */ + createdAfter?: string + /** Filter projects that gained new likes after this timestamp */ + likesReceivedAfter?: string + /** Filter projects that were remixed after this timestamp */ + remixesReceivedAfter?: string + /** If filter projects created by followees of logged-in user */ + fromFollowees?: boolean /** Field by which to order the results */ orderBy?: 'cTime' | 'uTime' | 'likeCount' | 'remixCount' | 'recentLikeCount' | 'recentRemixCount' /** Order in which to sort the results */ @@ -125,6 +134,49 @@ export async function getProject(owner: string, name: string) { return __adaptProjectData(await client.get(`/project/${encode(owner, name)}`)) } +export enum ExploreOrder { + MostLikes = 'likes', + MostRemixes = 'remix', + FollowingCreated = 'following' +} + +export type ExploreParams = { + order: ExploreOrder + count: number +} + +/** Get project list for explore purpose */ +export async function exploreProjects({ order, count }: ExploreParams) { + // count within the last month + const countAfter = timeStringify(dayjs().subtract(1, 'month').valueOf()) + const p: ListProjectParams = { + isPublic: IsPublic.public, + owner: ownerAll, + pageSize: count, + pageIndex: 1 + } + switch (order) { + case ExploreOrder.MostLikes: + p.likesReceivedAfter = countAfter + p.orderBy = 'recentLikeCount' + p.sortOrder = 'desc' + break + case ExploreOrder.MostRemixes: + p.remixesReceivedAfter = countAfter + p.orderBy = 'recentRemixCount' + p.sortOrder = 'desc' + break + case ExploreOrder.FollowingCreated: + p.fromFollowees = true + p.createdAfter = countAfter + p.orderBy = 'cTime' + p.sortOrder = 'desc' + break + } + const listResult = await listProject(p) + return listResult.data +} + /** * Check if given project liked by current logged-in user. * If not logged in, `false` will be returned. diff --git a/spx-gui/src/components/community/CommunityHeader.vue b/spx-gui/src/components/community/CommunityHeader.vue new file mode 100644 index 000000000..ad56bed8d --- /dev/null +++ b/spx-gui/src/components/community/CommunityHeader.vue @@ -0,0 +1,47 @@ + + + + + + + diff --git a/spx-gui/src/components/community/CommunityNavbar.vue b/spx-gui/src/components/community/CommunityNavbar.vue index 462b8bc6d..05c65f8be 100644 --- a/spx-gui/src/components/community/CommunityNavbar.vue +++ b/spx-gui/src/components/community/CommunityNavbar.vue @@ -2,7 +2,9 @@