Replace hardcoded slice(6) with slice("speeches/".length)

The magic number 6 is the length of the literal "speeches/" prefix these
four call sites strip off an ArangoDB-style id — spelling it out makes that
relationship explicit and survives a future rename of the prefix without a
silent off-by-N bug. Also swap response.statusText for response.status in
fetchTalk's error message: statusText is frequently empty (HTTP/2 drops the
reason phrase), so the numeric code is the more reliable thing to show.

This mirrors a fix already made directly on rixdagen-prod's production
branch (commit 9a87111) that hadn't been brought upstream yet.
main
Lasse Server 5 days ago
parent 7ea92c9366
commit 291dcebcb8
  1. 2
      frontend/src/api.ts
  2. 2
      frontend/src/components/ResultsTable.tsx
  3. 2
      frontend/src/components/TalkView.tsx
  4. 2
      frontend/src/context/TalkDrawerContext.tsx
  5. 2
      frontend/src/utils/markdown.ts

@ -162,7 +162,7 @@ export async function fetchTalk(id: string): Promise<any> {
headers: getSessionHeaders(),
});
if (!response.ok) {
throw new Error(`Failed to fetch talk: ${response.statusText}`);
throw new Error(`Failed to fetch talk: ${response.status}`);
}
return response.json();
}

@ -74,7 +74,7 @@ export function ResultsTable({ results, exportResults, onLoadMore, nextBatchSize
<tbody>
{results.map((hit) => {
// Always use _id, and strip "speeches/" prefix for routing
const talkKey = hit._id?.startsWith("speeches/") ? hit._id.slice(6) : hit._id;
const talkKey = hit._id?.startsWith("speeches/") ? hit._id.slice("speeches/".length) : hit._id;
if (!talkKey) {
console.warn("Result hit missing _id:", hit);
}

@ -77,7 +77,7 @@ export function TalkView() {
const idString = typeof rawId === 'object' && rawId !== null && '_id' in rawId
? (rawId as any)._id
: String(rawId);
const result = idString.startsWith("speeches/") ? idString.slice(6) : idString;
const result = idString.startsWith("speeches/") ? idString.slice("speeches/".length) : idString;
return result;
};
const previousId = normalizeTalkId(previousTalk);

@ -10,7 +10,7 @@ const TalkDrawerContext = createContext<TalkDrawerContextValue | null>(null);
/** Strips the ArangoDB "speeches/" collection prefix so callers can pass either form. */
export function normalizeTalkId(rawId: string): string {
return rawId.startsWith("speeches/") ? rawId.slice(6) : rawId;
return rawId.startsWith("speeches/") ? rawId.slice("speeches/".length) : rawId;
}
export function TalkDrawerProvider({ children }: { children: ReactNode }) {

@ -28,7 +28,7 @@ export const convertMarkdownToHtml = (markdown: string, sources?: ChatSource[]):
if (raw.startsWith("documents/")) {
talkPathByIndex.set(i + 1, `/motion/${raw.slice("documents/".length)}`);
} else {
const key = raw.startsWith("speeches/") ? raw.slice(6) : raw;
const key = raw.startsWith("speeches/") ? raw.slice("speeches/".length) : raw;
if (key) talkPathByIndex.set(i + 1, `/talk/${key}`);
}
});

Loading…
Cancel
Save