From 5f60a96650fbf8d34a0f770fc447bbb9bc018d75 Mon Sep 17 00:00:00 2001 From: Koen Klaren Date: Sat, 9 Mar 2024 12:11:57 +0100 Subject: [PATCH] Rename id -> hash --- frontend/api.ts | 3 ++- frontend/components/PlayerContext.tsx | 21 +++++++++---------- frontend/components/SampleItem/SampleItem.tsx | 2 +- .../components/preferences/VersionSection.tsx | 6 +++--- frontend/config.ts | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/frontend/api.ts b/frontend/api.ts index 683d91c..6e3198b 100644 --- a/frontend/api.ts +++ b/frontend/api.ts @@ -6,7 +6,7 @@ export interface Sample { // from server path: string; name: string; - id: string; + hash: string; mtime: number; categories: string[]; @@ -27,6 +27,7 @@ export async function fetchSamples(signal?: AbortSignal): Promise { const data = await res.json(); return data.samples.map((sampleData: any) => ({ ...sampleData, + hash: sampleData.id, mtime: sampleData.mtime * 1000, key: sampleData.path, url: `${url}/${sampleData.path}`, diff --git a/frontend/components/PlayerContext.tsx b/frontend/components/PlayerContext.tsx index 3372ae9..81efcf4 100644 --- a/frontend/components/PlayerContext.tsx +++ b/frontend/components/PlayerContext.tsx @@ -14,7 +14,7 @@ import { type Search } from '../helpers/Search'; import { type SampleListImperativeHandle } from './SampleList/SampleList'; interface PlayerContextValue { - playRandomSampleById(id: string): void; + playRandomSampleByHash(hash: string): void; playRandomFilteredSample(): void; } @@ -56,10 +56,10 @@ export function PlayerContextProvider( [playRandomSample, filteredSamples], ); - /** Play a random sample by its ID (note that ID is not unique). */ - const playRandomSampleById = useCallback( - (id: string) => - playRandomSample(samples.filter((sample) => sample.id === id)), + /** Play a random sample by its hash. */ + const playRandomSampleByHash = useCallback( + (hash: string) => + playRandomSample(samples.filter((sample) => sample.hash === hash)), [samples, playRandomSample], ); @@ -86,18 +86,17 @@ export function PlayerContextProvider( .filter((part) => part !== ''); pathParts.forEach((part) => { - // If part is an ID, play sample by ID. Otherwise, try to search for - // a sample with the part as a query. - playRandomSampleById(part) || playRandomSampleByQuery(part); + // Try to play a sample matching the hash, then the query + playRandomSampleByHash(part) || playRandomSampleByQuery(part); }); - }, [samples, playRandomSampleById, playRandomSampleByQuery]); + }, [samples, playRandomSampleByHash, playRandomSampleByQuery]); const playerContextValue = useMemo( () => ({ - playRandomSampleById, + playRandomSampleByHash, playRandomFilteredSample, }), - [playRandomSampleById, playRandomFilteredSample], + [playRandomSampleByHash, playRandomFilteredSample], ); return ( diff --git a/frontend/components/SampleItem/SampleItem.tsx b/frontend/components/SampleItem/SampleItem.tsx index 45aa5c2..01cdb3c 100644 --- a/frontend/components/SampleItem/SampleItem.tsx +++ b/frontend/components/SampleItem/SampleItem.tsx @@ -124,7 +124,7 @@ export function SampleItem(props: SampleItemProps) { title="Copy URL" onClick={async () => { const url = new URL( - sample.id, + sample.hash, new URL(config.baseUrl, document.baseURI), ); await navigator.clipboard.writeText(url.href); diff --git a/frontend/components/preferences/VersionSection.tsx b/frontend/components/preferences/VersionSection.tsx index 6a5f55c..7b2f253 100644 --- a/frontend/components/preferences/VersionSection.tsx +++ b/frontend/components/preferences/VersionSection.tsx @@ -12,7 +12,7 @@ export function VersionSection(): JSX.Element { } function VersionInfo(): JSX.Element { - const { playRandomSampleById } = useContext(PlayerContext)!; + const { playRandomSampleByHash } = useContext(PlayerContext)!; return (
@@ -23,10 +23,10 @@ function VersionInfo(): JSX.Element { Soundboard v{config.versionNumber} { e.preventDefault(); - playRandomSampleById(config.versionSampleId); + playRandomSampleByHash(config.versionSampleHash); }} > {config.versionName} diff --git a/frontend/config.ts b/frontend/config.ts index b540a51..2a31b77 100644 --- a/frontend/config.ts +++ b/frontend/config.ts @@ -1,7 +1,7 @@ export const config = { versionNumber: '3.4.2', versionName: 'je moet niet kijken, je moet zien', - versionSampleId: '1098b172', + versionSampleHash: '1098b172', repositoryUrl: 'https://github.com/team-thyme/soundboard', baseUrl: (process.env.BASE_URL || '/').replace(/\/$/, '') + '/', apiBaseUrl: (process.env.API_BASE_URL || 'http://localhost:32658').replace(