Skip to content
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

Routes for community #947

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions spx-gui/src/components/share/SharePage.vue

This file was deleted.

9 changes: 9 additions & 0 deletions spx-gui/src/pages/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-env node */
module.exports = {
extends: ['../../.eslintrc.cjs'],
rules: {
// Page components will not be used by name in other components' template.
// Disable this rule to simplify naming of page components.
'vue/multi-word-component-names': 'off'
}
}
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/explore.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Explore</div>
</template>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Home</div>
</template>
4 changes: 4 additions & 0 deletions spx-gui/src/pages/community/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template>
<header>Community Navbar</header>
<router-view />
</template>
22 changes: 22 additions & 0 deletions spx-gui/src/pages/community/project.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<RunnerContainer v-if="project != null" mode="share" :project="project" />
<UILoading :visible="project == null" cover />
</template>

<script setup lang="ts">
import { useAsyncComputed } from '@/utils/utils'
import { Project } from '@/models/project'
import RunnerContainer from '@/components/project/runner/RunnerContainer.vue'
import { UILoading } from '@/components/ui'

const props = defineProps<{
owner: string
name: string
}>()

const project = useAsyncComputed(async () => {
const p = new Project()
await p.loadFromCloud(props.owner, props.name)
return p
})
</script>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/projects.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Projects</div>
</template>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/user/followers.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Followers</div>
</template>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/user/following.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Following</div>
</template>
10 changes: 10 additions & 0 deletions spx-gui/src/pages/community/user/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<h2>User {{ name }}</h2>
<router-view />
</template>

<script setup lang="ts">
defineProps<{
name: string
}>()
</script>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/user/likes.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Likes</div>
</template>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/user/overview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Overview</div>
</template>
3 changes: 3 additions & 0 deletions spx-gui/src/pages/community/user/projects.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Projects</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</EditorContextProvider>
</template>
<template v-else>
<!-- TODO: remove me -->
<div class="my-projects">
<div class="header">
{{ $t({ en: 'My projects', zh: '我的项目' }) }}
Expand All @@ -43,13 +44,8 @@ import { useRouter } from 'vue-router'
import type { ProjectData } from '@/apis/project'
import { useUserStore } from '@/stores'
import { AutoSaveMode, Project } from '@/models/project'
import TopNav from '@/components/top-nav/TopNav.vue'
import ProjectList from '@/components/project/ProjectList.vue'
import { useCreateProject } from '@/components/project'
import { getProjectEditorRoute } from '@/router'
import { useMessageHandle, useQuery } from '@/utils/exception'
import EditorContextProvider from './EditorContextProvider.vue'
import ProjectEditor from './ProjectEditor.vue'
import { clear } from '@/models/common/local'
import {
UIButton,
Expand All @@ -61,6 +57,11 @@ import {
} from '@/components/ui'
import { useI18n } from '@/utils/i18n'
import { useNetwork } from '@/utils/network'
import TopNav from '@/components/top-nav/TopNav.vue'
import EditorContextProvider from '@/components/editor/EditorContextProvider.vue'
import ProjectEditor from '@/components/editor/ProjectEditor.vue'
import ProjectList from '@/components/project/ProjectList.vue'
import { useCreateProject } from '@/components/project'

const LOCAL_CACHE_KEY = 'GOPLUS_BUILDER_CACHED_PROJECT'

Expand Down
79 changes: 72 additions & 7 deletions spx-gui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,92 @@ export function getProjectEditorRoute(projectName: string) {
return `/editor/${projectName}`
}

export function getProjectPageRoute(owner: string, name: string) {
return `/project/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`
}

export type UserTab = 'overview' | 'projects' | 'likes' | 'followers' | 'following'

export function getUserPageRoute(name: string, tab: UserTab = 'overview') {
const base = `/user/${encodeURIComponent(name)}`
if (tab === 'overview') return base
return `${base}/${tab}`
}

export function getProjectShareRoute(owner: string, name: string) {
return `/share/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`
return getProjectPageRoute(owner, name)
}

const routes: Array<RouteRecordRaw> = [
{ path: '/', redirect: '/editor' },
{
path: '/',
component: () => import('@/pages/community/index.vue'),
children: [
{
path: '/',
component: () => import('@/pages/community/home.vue')
},
{
path: '/explore',
component: () => import('@/pages/community/explore.vue')
},
{
path: '/projects',
component: () => import('@/pages/community/projects.vue')
},
{
path: '/user/:name',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关于这种 path style,我在想如果对于资源集合咱们使用复数(比如 /projects),那对于特定资源实例如果用“复数集合+标识符“的格式看起来会不会更统一些?比如,/users/:name

另外,咱们不使用类似 twitter、github 那种资源所有者优先的 path style 的主要原因是什么?是关键词保留方面的吗?

Copy link
Collaborator Author

@nighca nighca Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关于这种 path style,我在想如果对于资源集合咱们使用复数(比如 /projects),那对于特定资源实例如果用“复数集合+标识符“的格式看起来会不会更统一些?比如,/users/:name

这个是目前 spx-backend HTTP 接口的路由风格,对于资源集合的操作(如列举),就用复数;对于单个资源,则单数 + 标识

你说的总是用复数的方式我觉得也 OK 的,只是这二者间,这里会倾向跟已有的风格一致

另外,咱们不使用类似 twitter、github 那种资源所有者优先的 path style 的主要原因是什么?是关键词保留方面的吗?

Github 是 /:user/:repo,Twitter 是 /:user/status/:id,在 :user 这里确实会容易有路由冲突的问题,虽然不是不能解决,不过感觉好处有限

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关于这种 path style,我在想如果对于资源集合咱们使用复数(比如 /projects),那对于特定资源实例如果用“复数集合+标识符“的格式看起来会不会更统一些?比如,/users/:name

这个是目前 HTTP 接口的路由风格,对于资源集合的操作(如列举),就用复数;对于单个资源,则单数 + 标识

你说的总是用复数的方式我觉得也 OK 的,只是这二者间,这里会倾向跟已有的风格一致

其实我挺想改一下接口的整体风格的,改得更 RESTful 些,只不过牵扯到兼容性问题不太好下手。

我在想对于类似 path style 这种后期很难再做改动的东西来说,咱们是不是可以尽量向 github 靠拢?感觉他们的大多数风格都挺优雅的。

另外,咱们不使用类似 twitter、github 那种资源所有者优先的 path style 的主要原因是什么?是关键词保留方面的吗?

Github 是 /:user/:repo,Twitter 是 /:user/status/:id,在 :user` 这里确实会容易有路由冲突的问题,虽然不是不能解决,不过感觉好处有限

嗯想了一下好处是有限,主要好处可能是短一点分享的时候会方便些。咱们可以先不用这种风格。就算后面因为某些原因想用了也可以换过去,而且应该不会造成什么兼容性问题。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在想对于类似 path style 这种后期很难再做改动的东西来说,咱们是不是可以尽量向 github 靠拢?感觉他们的大多数风格都挺优雅的。

是的,不过 github 自己也有一些混乱的地方;比如 pull 跟 commit 都是像上面说的“对资源集合复数,对单个资源单数”(这个风格我觉得也是逻辑自洽的),而 issue、project 这些又像你说的“都是复数”

就算后面因为某些原因想用了也可以换过去,而且应该不会造成什么兼容性问题。

哈哈哈会有问题吧,如果用户名叫“explore”或者“projects”,他的个人主页就没法访问了..Twitter 用户应该就不能起名叫“explore”或者“notifications”?这个是我不喜欢这种路由的主要原因

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以及 Github 的 /:owner/:repo 这种路由风格的实施好像后来也遇到了障碍,对于 organization,其 repo 的路由还是 /:owner/:repo,但是

这些就变成多了个 /orgs 前缀;我不太清楚这里边具体的原因,但是这种不一致应该是不得已

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果用户名叫“explore”或者“projects”,他的个人主页就没法访问了

对是的,刚我也想到了,但我想的是 oauth provider 会帮咱们屏蔽掉一些关键词。不过我忽略了咱们后面还会引入邮箱登录允许自定义用户名……

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以及 Github 的 /:owner/:repo 这种路由风格的实施好像后来也遇到了障碍,对于 organization,其 repo 的路由还是 /:owner/:repo,但是

这些就变成多了个 /orgs 前缀;我不太清楚这里边具体的原因,但是这种不一致应该是不得已

嗯同意不要用这种风格了,感觉引入的问题远比好处多

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,不过 github 自己也有一些混乱的地方;比如 pull 跟 commit 都是像上面说的“对资源集合复数,对单个资源单数”(这个风格我觉得也是逻辑自洽的),而 issue、project 这些又像你说的“都是复数”

嗯 github 确实也不是完全统一的……

对于 /users/:user 这种风格来说,应该是把每一级都看作“目录”。所以 /users 表示目录本身,/users/:user 表示目录下的具体项。

倒也不是非得遵循这种目录结构风格。想了一下如果遵循“对资源集合复数,对单个资源单数”,这样接口改动也会更小一些。

component: () => import('@/pages/community/user/index.vue'),
props: true,
children: [
{
path: '',
component: () => import('@/pages/community/user/overview.vue')
},
{
path: 'projects',
component: () => import('@/pages/community/user/projects.vue')
},
{
path: 'likes',
component: () => import('@/pages/community/user/likes.vue')
},
{
path: 'followers',
component: () => import('@/pages/community/user/followers.vue')
},
{
path: 'following',
component: () => import('@/pages/community/user/following.vue')
}
]
},
{
path: '/project/:owner/:name',
component: () => import('@/pages/community/project.vue'),
props: true
}
]
},
{
path: '/editor',
component: () => import('@/components/editor/EditorHomepage.vue')
redirect: '/'
},
{
path: '/editor/:projectName',
component: () => import('@/components/editor/EditorHomepage.vue')
component: () => import('@/pages/editor/index.vue')
},
{
path: '/callback', // TODO: remove me
redirect: '/sign-in/callback'
},
{
path: '/callback',
component: () => import('@/components/SigninCallback.vue')
path: '/sign-in/callback',
component: () => import('@/pages/sign-in/callback.vue')
},
{
path: '/share/:owner/:name',
component: () => import('@/components/share/SharePage.vue')
redirect: (to) => getProjectPageRoute(to.params.owner as string, to.params.name as string)
}
]

Expand Down
Loading