diff --git a/src/lib/components/FeedRow.svelte b/src/lib/components/FeedRow.svelte index 720c4a0..bc743c8 100644 --- a/src/lib/components/FeedRow.svelte +++ b/src/lib/components/FeedRow.svelte @@ -1,4 +1,5 @@ + + diff --git a/src/routes/[code]/[id]/+page.svelte b/src/routes/[code]/[id]/+page.svelte new file mode 100644 index 0000000..9a59330 --- /dev/null +++ b/src/routes/[code]/[id]/+page.svelte @@ -0,0 +1,44 @@ + + +{#if loading} +
+

Loading

+
+{:else if postType === "note"} + +{:else if postType === "question"} + +{:else} +
+

Post not found

+ Home +
+{/if} diff --git a/src/routes/notes/+page.svelte b/src/routes/notes/+page.svelte index 5986611..4031465 100644 --- a/src/routes/notes/+page.svelte +++ b/src/routes/notes/+page.svelte @@ -3,6 +3,7 @@ import { onMount } from "svelte"; import FeedRow from "$lib/components/FeedRow.svelte"; import UnitFilter from "$lib/components/UnitFilter.svelte"; + import { postPath } from "$lib/paths"; import { timeAgo } from "$lib/time"; import type { NoteDoc, UnitDoc } from "$lib/types"; @@ -79,7 +80,7 @@ {:else} {#each visible as note}
-

- {#if unit}{unit.code}{unit.code2 - ? ` / ${unit.code2}` - : ""}{/if}{#if unit && topic} - · - {/if}{#if topic}{topic.name}{/if} -

+
+ {#if unit} + + {unit.code}{unit.code2 ? ` / ${unit.code2}` : ""} + + {/if} + {#if unit && topic} + {" · "} + {/if} + {#if topic} + {topic.name} + {/if} +
{#if editMode} unit._id === unitId)?.code ?? ""; if (useCustomUnit && customUnit.trim()) { - const existing = units.find( - (u) => u.code.toLowerCase() === customUnit.trim().toUpperCase(), + unitCode = customUnit.trim().toUpperCase(); + const existing = units.find((u) => + [u.code, u.code2].some((code) => code?.toUpperCase() === unitCode), ); if (existing) { unitId = existing._id; + unitCode = existing.code; } else { unitId = (await mutation("units:createCustom", { - code: customUnit.trim().toUpperCase(), - name: customUnit.trim().toUpperCase(), + code: unitCode, + name: unitCode, })) as string; } } @@ -73,7 +77,7 @@ unitId, })) as string; - goto(`/notes/${id}`); + goto(postPath(unitCode, id)); } catch (err: any) { error = err.message ?? "Failed to publish note"; } finally { diff --git a/src/routes/post/question/+page.svelte b/src/routes/post/question/+page.svelte index 7b9a2d4..f64a6b7 100644 --- a/src/routes/post/question/+page.svelte +++ b/src/routes/post/question/+page.svelte @@ -5,6 +5,7 @@ import { onMount } from "svelte"; import { get } from "svelte/store"; import MarkdownEditor from "$lib/components/MarkdownEditor.svelte"; + import { postPath } from "$lib/paths"; import type { TopicDoc, UnitDoc } from "$lib/types"; let topics: TopicDoc[] = $state([]); @@ -51,16 +52,19 @@ loading = true; try { let unitId = selectedUnitId; + let unitCode = units.find((unit) => unit._id === unitId)?.code ?? ""; if (useCustomUnit && customUnit.trim()) { - const existing = units.find( - (u) => u.code.toLowerCase() === customUnit.trim().toUpperCase(), + unitCode = customUnit.trim().toUpperCase(); + const existing = units.find((u) => + [u.code, u.code2].some((code) => code?.toUpperCase() === unitCode), ); if (existing) { unitId = existing._id; + unitCode = existing.code; } else { unitId = (await mutation("units:createCustom", { - code: customUnit.trim().toUpperCase(), - name: customUnit.trim().toUpperCase(), + code: unitCode, + name: unitCode, })) as string; } } @@ -73,7 +77,7 @@ unitId, })) as string; - goto(`/questions/${id}`); + goto(postPath(unitCode, id)); } catch (err: any) { error = err.message ?? "Failed to post question"; } finally { diff --git a/src/routes/questions/+page.svelte b/src/routes/questions/+page.svelte index 2df85ef..f14110b 100644 --- a/src/routes/questions/+page.svelte +++ b/src/routes/questions/+page.svelte @@ -3,6 +3,7 @@ import { onMount } from "svelte"; import FeedRow from "$lib/components/FeedRow.svelte"; import UnitFilter from "$lib/components/UnitFilter.svelte"; + import { postPath } from "$lib/paths"; import { timeAgo } from "$lib/time"; import type { QuestionDoc, UnitDoc } from "$lib/types"; @@ -86,7 +87,7 @@ {:else} {#each visible as question} {:else} Notes

{#each notes as note} Questions

{#each questions as question} {#if selectedUnit.description} -

{selectedUnit.description}

+

+ {selectedUnit.description} +

{/if} {#if contentLoading} @@ -86,7 +92,7 @@

Notes

{#each notes as note} Questions

{#each questions as question} Notes

{#each notes as note} Questions

{#each questions as question}