Skip to content

Commit

Permalink
Rename id -> hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesoptier committed Mar 9, 2024
1 parent 018eea6 commit 5f60a96
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion frontend/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Sample {
// from server
path: string;
name: string;
id: string;
hash: string;
mtime: number;
categories: string[];

Expand All @@ -27,6 +27,7 @@ export async function fetchSamples(signal?: AbortSignal): Promise<Sample[]> {
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}`,
Expand Down
21 changes: 10 additions & 11 deletions frontend/components/PlayerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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],
);

Expand All @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/SampleItem/SampleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/preferences/VersionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function VersionSection(): JSX.Element {
}

function VersionInfo(): JSX.Element {
const { playRandomSampleById } = useContext(PlayerContext)!;
const { playRandomSampleByHash } = useContext(PlayerContext)!;

return (
<div className="VersionInfo">
Expand All @@ -23,10 +23,10 @@ function VersionInfo(): JSX.Element {
Soundboard v{config.versionNumber}
</a>
<a
href={`${config.baseUrl}${config.versionSampleId}`}
href={`${config.baseUrl}${config.versionSampleHash}`}
onClick={(e) => {
e.preventDefault();
playRandomSampleById(config.versionSampleId);
playRandomSampleByHash(config.versionSampleHash);
}}
>
{config.versionName}
Expand Down
2 changes: 1 addition & 1 deletion frontend/config.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 5f60a96

Please sign in to comment.