Skip to content

Commit 5a95e4f

Browse files
committed
feat: add license information to song page
1 parent f2fa398 commit 5a95e4f

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

shared/validation/song/constants.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,16 @@ export const UploadConst = deepFreeze({
8989
},
9090

9191
licenses: {
92-
cc_by_sa: 'Creative Commons - Attribution-ShareAlike 4.0',
93-
standard: 'Standard License',
92+
cc_by_sa: {
93+
name: 'Creative Commons - Attribution-ShareAlike 4.0',
94+
description:
95+
'You can copy, modify, and distribute this song, even for commercial purposes, as long as you credit the author and provide a link to the song. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.\n\nFor more information, please visit the [Creative Commons website](https://creativecommons.org/licenses/by-sa/4.0/).',
96+
},
97+
standard: {
98+
name: 'Standard License',
99+
description:
100+
"The author reserves all rights. You may not use this song without the author's permission.",
101+
},
94102
},
95103

96104
visibility: {

web/src/modules/song/components/SongPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Image from 'next/image';
33

44
import axios from '@web/src/lib/axios';
55

6+
import { LicenseInfo } from './client/LicenseInfo';
67
import { SongDetails } from './SongDetails';
78
import {
89
DownloadSongButton,
@@ -62,6 +63,7 @@ export async function SongPage({ id }: { id: string }) {
6263
<p className='leading-tight whitespace-pre-line'>
6364
{song.description}
6465
</p>
66+
<LicenseInfo license={song.license} />
6567
</div>
6668
</div>
6769

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use client';
2+
3+
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
4+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5+
import { UploadConst } from '@shared/validation/song/constants';
6+
import Markdown from 'react-markdown';
7+
8+
import {
9+
Tooltip,
10+
TooltipContent,
11+
TooltipTrigger,
12+
} from '@web/src/modules/shared/components/tooltip';
13+
14+
export const LicenseTooltip = ({ description }: { description: string }) => {
15+
return (
16+
<Tooltip>
17+
<TooltipTrigger asChild>
18+
<button type='button' className='text-zinc-500 cursor-default'>
19+
<FontAwesomeIcon icon={faQuestionCircle} />
20+
</button>
21+
</TooltipTrigger>
22+
<TooltipContent className='max-w-64 px-2.5 py-2 flex flex-col gap-2 [&_a]:text-blue-400 [&_a:hover]:text-blue-300'>
23+
{<Markdown>{description}</Markdown>}
24+
</TooltipContent>
25+
</Tooltip>
26+
);
27+
};
28+
29+
export const LicenseInfo = ({ license }: { license: string }) => {
30+
// @ts-expect-error - read-only object cannot be indexed with a string
31+
const licenseInfo = UploadConst.licenses[license];
32+
33+
if (!licenseInfo) {
34+
return null;
35+
}
36+
37+
return (
38+
<div className='flex items-center gap-3'>
39+
<p className='text-sm text-zinc-400'>License</p>
40+
<p className='text-sm'>{licenseInfo.name}</p>
41+
<LicenseTooltip description={licenseInfo.description} />
42+
</div>
43+
);
44+
};

web/src/modules/song/components/client/SongForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@ export const SongForm = ({
295295
{...register('license')}
296296
>
297297
{Object.entries(UploadConst.licenses).map(
298-
([key, value]: [string, string]) => (
298+
// @ts-expect-error - TS doesn't like the destructuring here
299+
([key, { name }]: [string, string]) => (
299300
<Option key={key} value={key}>
300-
{value}
301+
{name}
301302
</Option>
302303
),
303304
)}

0 commit comments

Comments
 (0)