Skip to content

Commit f3837b7

Browse files
committed
✨ Enable to use url slug in workbook page (#2020)
1 parent 50f9d73 commit f3837b7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/lib/components/WorkBooks/TitleTableBodyCell.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
}
1111
1212
let { paddingLeft = 'pl-2 xs:pl-4', workbook }: Props = $props();
13+
14+
function getUrlSlugFrom(workbook: WorkbookList): string {
15+
const slug = workbook.urlSlug;
16+
17+
return slug ? slug : workbook.id.toString();
18+
}
1319
</script>
1420

1521
<TableBodyCell class="w-2/5 {paddingLeft} pr-4">
@@ -18,7 +24,7 @@
1824
>
1925
<PublicationStatusLabel isPublished={workbook.isPublished} />
2026
<a
21-
href="/workbooks/{workbook.id}"
27+
href="/workbooks/{getUrlSlugFrom(workbook)}"
2228
class="flex-1 font-medium xs:text-lg text-primary-600 hover:underline dark:text-primary-500 truncate"
2329
aria-labelledby="View details for workbook: {workbook.title}"
2430
>

src/lib/components/WorkBooks/WorkBookBaseTable.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
TableHeadCell,
1111
} from 'svelte-5-ui-lib';
1212
13-
import { WorkBookType, type WorkbooksList } from '$lib/types/workbook';
13+
import { WorkBookType, type WorkbooksList, type WorkbookList } from '$lib/types/workbook';
1414
import { TaskGrade, type TaskResults } from '$lib/types/task';
1515
import type { Roles } from '$lib/types/user';
1616
@@ -22,6 +22,7 @@
2222
import AcceptedCounter from '$lib/components/SubmissionStatus/AcceptedCounter.svelte';
2323
2424
import { canRead, canEdit, canDelete } from '$lib/utils/authorship';
25+
import WorkBookList from './WorkBookList.svelte';
2526
2627
interface Props {
2728
workbookType: WorkBookType;
@@ -41,6 +42,12 @@
4142
function getTaskResult(workbookId: number): TaskResults {
4243
return taskResults?.get(workbookId) ?? [];
4344
}
45+
46+
function getUrlSlugFrom(workbook: WorkbookList): string {
47+
const slug = workbook.urlSlug;
48+
49+
return slug ? slug : workbook.id.toString();
50+
}
4451
</script>
4552

4653
<!-- FIXME: 問題集の種類別にコンポーネントを分ける -->
@@ -123,7 +130,7 @@
123130
class="flex justify-center items-center space-x-3 min-w-[96px] max-w-[120px] text-gray-700 dark:text-gray-300"
124131
>
125132
{#if canEdit(userId, workbook.authorId, role, workbook.isPublished)}
126-
<a href="/workbooks/edit/{workbook.id}">編集</a>
133+
<a href="/workbooks/edit/{getUrlSlugFrom(workbook)}">編集</a>
127134
{/if}
128135

129136
{#if canDelete(userId, workbook.authorId)}

0 commit comments

Comments
 (0)