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

router-linkのto属性でオブジェクトの使用・HyperText型のurl(string型)をpath(RouteLocationNamedRaw)に #336

Merged
merged 6 commits into from
Aug 19, 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
3 changes: 2 additions & 1 deletion src/components/Index/PageInfoPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import { toRef } from 'vue'
import Icon from '/@/components/UI/Icon.vue'
import useRouteInfo from '/@/lib/routeInfo'
import { RouteLocationNamedRaw } from 'vue-router'

interface Props {
name: string
path: string
path: RouteLocationNamedRaw
}

const props = defineProps<Props>()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Index/PageInfoPanels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pages = routes.filter(route => route.name != 'Top')
v-for="page in pages"
:key="page.name"
:name="page.name"
:path="page.path"
:path="{ name: page.name }"
/>
</ul>
</template>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Layout/ContentHeader.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { RouteLocationNamedRaw } from 'vue-router'
import Icon from '/@/components/UI/Icon.vue'

type HeaderText = {
title: string
url: string
path: RouteLocationNamedRaw
}

interface Props {
Expand All @@ -27,7 +28,7 @@ const props = defineProps<Props>()
/>
<router-link
v-if="index !== props.headerTexts.length - 1"
:to="headerText.url"
:to="headerText.path"
:class="$style.link"
>
{{ headerText.title }}
Expand Down
14 changes: 9 additions & 5 deletions src/components/NavigationBar/NavigationLinksItem.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script lang="ts" setup>
import { computed, toRef } from 'vue'
import { useRoute } from 'vue-router'
import { useRoute, RouteLocationNamedRaw } from 'vue-router'
import Icon from '/@/components/UI/Icon.vue'
import useRouteInfo from '/@/lib/routeInfo'
import { routes } from '/@/router/index'

interface Props {
name: string
path: string
path: RouteLocationNamedRaw
}

const currentRoute = useRoute()
Expand All @@ -16,10 +17,13 @@ const props = defineProps<Props>()
const routeInfo = useRouteInfo(toRef(props, 'name'))

const isActive = computed(() => {
if (props.path === '/') return currentRoute.path === props.path
const path = routes.find(route => route.name === props.path.name)?.path
if (path === undefined) {
return false
}
return (
currentRoute.path === props.path ||
currentRoute.path.startsWith(`${props.path}/`)
currentRoute.name === props.path.name ||
currentRoute.path.startsWith(`${path}/`)
Copy link
Member

Choose a reason for hiding this comment

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

これでも多分動きはするのですが、pathundefinedだったときにstartsWith('undefined/')になっちゃってあんまりきれいじゃないので僕が書いたようにundefinedのときは明示的にfalseを返すようにした方がよさそうです(テンプレートリテラル内にstring型以外を入れられないようにするeslintのルールも確かあったはずです)

)
})
</script>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Projects/ProjectItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ defineProps<Props>()
</script>

<template>
<router-link :to="`/projects/${project.id}/edit`" :class="$style.link">
<router-link
:to="{ name: 'Project', params: { projectId: project.id } }"
:class="$style.link"
>
<div :class="$style.container">
<p :class="$style.name">{{ project.name }}</p>
<p :class="$style.duration">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const toStringIfArray = (s: string | undefined | readonly string[]) =>
const useParam = (paramName: string): ComputedRef<string> => {
const route = useRoute()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return computed(() => toStringIfArray(route.params[paramName])!)
return computed(() => toStringIfArray(route.params[paramName]) ?? 'undefined')
}

export default useParam
13 changes: 7 additions & 6 deletions src/lib/routeInfo.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { computed, ComputedRef, Ref } from 'vue'
import { RouteLocationNamedRaw } from 'vue-router'

interface routeinfo {
name: string
path: string
path: RouteLocationNamedRaw
icon: string
description: string
}

export const routes: routeinfo[] = [
{
name: 'Top',
path: '/',
path: { name: 'Index' },
icon: 'mdi:apps',
description: 'ポートフォリオの設定を変更します'
},
{
name: 'Profile',
path: '/user',
path: { name: 'Profile' },
icon: 'mdi:account-circle-outline',
description: '掲載するアカウントや自己紹介を編集します'
},
Expand All @@ -28,13 +29,13 @@ export const routes: routeinfo[] = [
// },
{
name: 'Contests',
path: '/contests',
path: { name: 'Contests' },
icon: 'mdi:trophy-outline',
description: '出場した大会を追加・編集します'
},
{
name: 'Projects',
path: '/projects',
path: { name: 'Projects' },
icon: 'mdi:clipboard-file-outline',
description: 'プロジェクトの期間や説明文を編集します'
}
Expand All @@ -47,7 +48,7 @@ const getMessage = (name: string): routeinfo => {
// Default Value
return {
name: 'Loading',
path: '',
path: {},
icon: 'eos-icons:bubble-loading',
description: 'Loading'
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Contest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ const contestTeams: ContestTeam[] = (
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[
{ title: 'Contests', url: '/contests' },
{ title: contestDetail.name, url: `/contests/${contestId}` }
{ title: 'Contests', path: { name: 'Contests' } },
{
title: contestDetail.name,
path: { name: 'Contest', params: { contestId: contestId } }
}
]"
detail="コンテストの詳細です。"
:class="$style.header"
Expand Down
12 changes: 9 additions & 3 deletions src/pages/ContestEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ const deleteContest = async () => {
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[
{ title: 'Contests', url: '/contests' },
{ title: contestDetail.name, url: `/contests/${contestId}` },
{ title: 'Edit', url: `/contests/${contestId}/edit` }
{ title: 'Contests', path: { name: 'Contests' } },
{
title: contestDetail.name,
path: { name: 'Contest', params: { contestId: contestId } }
},
{
title: 'Edit',
path: { name: 'ContestEdit', params: { contestId: contestId } }
}
]"
detail="コンテストの情報を変更します。"
:class="$style.header"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ContestNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const createContest = async () => {
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[
{ title: 'Contests', url: '/contests' },
{ title: 'New', url: '/contests/new' }
{ title: 'Contests', path: { name: 'Contests' } },
{ title: 'New', path: { name: 'ContestNew' } }
]"
detail="コンテストを作成します。"
:class="$style.header"
Expand Down
19 changes: 14 additions & 5 deletions src/pages/ContestTeamEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,28 @@ const deleteContestTeam = async () => {
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[
{ title: 'Contests', url: '/contests' },
{ title: contest.name, url: `/contests/${contestId}` },
{ title: 'Contests', path: { name: 'Contests' } },
{
title: contest.name,
path: { name: 'Contest', params: { contestId: contestId } }
},
{
title: 'Teams',
url: `/contests/${contestId}`
path: { name: 'Contest', params: { contestId: contestId } }
},
{
title: contestTeam.name,
url: `/contests/${contestId}/teams/${contestTeamId}/edit`
path: {
name: 'ContestTeamEdit',
params: { contestId: contestId, teamId: contestTeamId }
}
},
{
title: 'Edit',
url: `/contests/${contestId}/teams/${contestTeamId}/edit`
path: {
name: 'ContestTeamEdit',
params: { contestId: contestId, teamId: contestTeamId }
}
}
]"
detail="コンテストチームの情報を変更します。"
Expand Down
14 changes: 10 additions & 4 deletions src/pages/ContestTeamNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ const createContestTeam = async () => {
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[
{ title: 'Contests', url: '/contests' },
{ title: contest.name, url: `/contests/${contestId}` },
{ title: 'Contests', path: { name: 'Contests' } },
{
title: contest.name,
path: { name: 'Contest', params: { contestId: contestId } }
},
{
title: 'Teams',
url: `/contests/${contestId}`
path: { name: 'Contest', params: { contestId: contestId } }
},
{ title: 'New', url: `/contests/${contestId}/teams/new` }
{
title: 'New',
path: { name: 'ContestTeamNew', params: { contestId: contestId } }
}
]"
detail="コンテストチームを追加します。"
:class="$style.header"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Contests.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const filteredContests = computed(() =>
<page-container>
<content-header
icon-name="mdi:trophy-outline"
:header-texts="[{ title: 'Contests', url: '/contests' }]"
:header-texts="[{ title: 'Contests', path: { name: 'Contests' } }]"
detail="コンテスト情報を変更します。"
:class="$style.header"
/>
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ const updateEvent = async () => {
<content-header
icon-name="mdi:calendar"
:header-texts="[
{ title: 'Events', url: '/events' },
{ title: event.name, url: `/events/${eventId}` }
{ title: 'Events', path: { name: 'Events' } },
{
title: event.name,
path: { name: 'Event', params: { id: eventId } }
}
]"
detail="イベントの詳細を確認します。"
:class="$style.header"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const filteredEventsBySearch = computed(() =>
<page-container>
<content-header
icon-name="mdi:calendar"
:header-texts="[{ title: 'Events', url: '/events' }]"
:header-texts="[{ title: 'Events', path: { name: 'Events' } }]"
detail="イベントの公開設定を変更します"
:class="$style.header"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PageContainer from '/@/components/Layout/PageContainer.vue'
<page-container>
<content-header
icon-name="mdi:apps"
:header-texts="[{ title: 'Top', url: '/' }]"
:header-texts="[{ title: 'Top', path: { name: 'Index' } }]"
detail="ポートフォリオの設定を変更します"
:class="$style.header"
/>
Expand Down
12 changes: 9 additions & 3 deletions src/pages/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ const handleDelete = (id: string) => {
<content-header
icon-name="mdi:clipboard-file-outline"
:header-texts="[
{ title: 'Projects', url: '/projects' },
{ title: projectDetail.name, url: `/projects/${projectId}/edit` },
{ title: 'Edit', url: `/projects/${projectId}/edit` }
{ title: 'Projects', path: { name: 'Projects' } },
{
title: projectDetail.name,
path: { name: 'Project', params: { projectId: projectId } }
},
{
title: 'Edit',
path: { name: 'Project', params: { projectId: projectId } }
}
]"
detail="プロジェクトの情報を変更します。"
:class="$style.header"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ProjectNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ const handleDelete = (id: string) => {
<content-header
icon-name="mdi:clipboard-file-outline"
:header-texts="[
{ title: 'Projects', url: '/projects' },
{ title: 'New', url: '/projects/new' }
{ title: 'Projects', path: { name: 'Projects' } },
{ title: 'New', path: { name: 'ProjectNew' } }
]"
detail="プロジェクトを作成します。"
:class="$style.header"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const filteredProjects = computed(() =>
<page-container>
<content-header
icon-name="mdi:clipboard-file-outline"
:header-texts="[{ title: 'Projects', url: '/projects' }]"
:header-texts="[{ title: 'Projects', path: { name: 'Projects' } }]"
detail="プロジェクトを変更します"
:class="$style.header"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { isMobile } = storeToRefs(useResponsiveStore())
<div :class="$style.headerContainer">
<content-header
icon-name="mdi:account-circle-outline"
:header-texts="[{ title: 'Profile', url: '/user' }]"
:header-texts="[{ title: 'Profile', path: { name: 'Profile' } }]"
detail="プロフィールを変更します。"
:class="$style.header"
/>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/UserAccountEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ const deleteAccount = async () => {
<content-header
icon-name="mdi:account-circle-outline"
:header-texts="[
{ title: 'Profile', url: '/user' },
{ title: 'Accounts', url: `/user/accounts` },
{ title: 'Profile', path: { name: 'Profile' } },
{ title: 'Accounts', path: { name: 'UserAccounts' } },
{
title: 'Edit',
url: `/user/accounts/edit`
path: { name: 'UserAccountEdit', params: { accountId: accountId } }
}
]"
detail="アカウント情報を編集します。"
Expand Down
6 changes: 3 additions & 3 deletions src/pages/UserAccountNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ const createNewAccount = async () => {
<content-header
icon-name="mdi:account-circle-outline"
:header-texts="[
{ title: 'Profile', url: '/user' },
{ title: 'Accounts', url: `/user/accounts` },
{ title: 'Profile', path: { name: 'Profile' } },
{ title: 'Accounts', path: { name: 'UserAccounts' } },
{
title: 'New',
url: `/user/accounts/new`
path: { name: 'UserAccountsNew' }
}
]"
detail="アカウントを登録します。"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/UserAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const me = (await apis.getMe()).data
<content-header
icon-name="mdi:account-circle-outline"
:header-texts="[
{ title: 'Profile', url: '/user' },
{ title: 'Accounts', url: '/user/accounts' }
{ title: 'Profile', path: { name: 'Profile' } },
{ title: 'Accounts', path: { name: 'UserAccounts' } }
]"
detail="アカウント情報を変更します。"
:class="$style.header"
Expand Down
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ContestTeamNew = () => import('/@/pages/ContestTeamNew.vue')
const ContestTeamEdit = () => import('/@/pages/ContestTeamEdit.vue')
const NotFound = () => import('/@/pages/NotFound.vue')

const routes = [
export const routes = [
{
path: '/',
name: 'Index',
Expand Down