-
- {#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}