Skip to content

Commit

Permalink
feat(coscrad-frontend): move audio panel to a drawer (#342)
Browse files Browse the repository at this point in the history
* WIP: building audio panel for index views

* WIP: make changes from PR

* WIP finish playlist detail presenter and index-to-detail flow

* WIP: converted audio-panel to explicit return

* fix issues after rebase

* fix: type error

* test(api): update stale snapshots

---------

Co-authored-by: Aaron Plahn <[email protected]>
  • Loading branch information
bsellars and aaron-plahn committed May 23, 2023
1 parent 9fce4f1 commit 05c565d
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when all of
"entities": [
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110110",
"lengthMilliseconds": 20000,
"mimeType": "audio/mpeg",
Expand All @@ -24,7 +24,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when all of
},
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110111",
"lengthMilliseconds": 23409,
"mimeType": "audio/mpeg",
Expand All @@ -44,7 +44,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when all of
},
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110113",
"lengthMilliseconds": 32989,
"mimeType": "audio/mpeg",
Expand All @@ -71,7 +71,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when some of
"entities": [
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110110",
"lengthMilliseconds": 20000,
"mimeType": "audio/mpeg",
Expand All @@ -90,7 +90,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when some of
},
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110111",
"lengthMilliseconds": 23409,
"mimeType": "audio/mpeg",
Expand All @@ -110,7 +110,7 @@ exports[`When fetching multiple resources GET /resources/audioItems when some of
},
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110113",
"lengthMilliseconds": 32989,
"mimeType": "audio/mpeg",
Expand Down Expand Up @@ -690,7 +690,7 @@ exports[`When fetching multiple resources GET /resources/mediaItems when all of
],
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 1",
"url": "https://www.metalmondays.com/1.mp3",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
},
{
"actions": [],
Expand All @@ -702,6 +702,16 @@ exports[`When fetching multiple resources GET /resources/mediaItems when all of
"titleEnglish": "cool video",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=3028_6d3b2a922b.mp4",
},
{
"actions": [],
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110003",
"lengthMilliseconds": 2500,
"mimeType": "audio/mpeg",
"tags": [],
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 2",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
},
],
"indexScopedActions": [],
}
Expand Down Expand Up @@ -749,7 +759,7 @@ exports[`When fetching multiple resources GET /resources/mediaItems when some of
],
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 1",
"url": "https://www.metalmondays.com/1.mp3",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
},
{
"actions": [],
Expand All @@ -761,6 +771,16 @@ exports[`When fetching multiple resources GET /resources/mediaItems when some of
"titleEnglish": "cool video",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=3028_6d3b2a922b.mp4",
},
{
"actions": [],
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110003",
"lengthMilliseconds": 2500,
"mimeType": "audio/mpeg",
"tags": [],
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 2",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
},
],
"indexScopedActions": [],
}
Expand Down Expand Up @@ -915,10 +935,15 @@ exports[`When fetching multiple resources GET /resources/playlists when all of t
"actions": [],
"episodes": [
{
"mediaItemUrl": "https://www.metalmondays.com/1.mp3",
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"mimeType": "audio/mpeg",
"name": "{eng}: The Wooden Boy",
},
{
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
"mimeType": "audio/mpeg",
"name": "{clc}: Down at the River",
},
],
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110501",
"name": {
Expand Down Expand Up @@ -959,10 +984,15 @@ exports[`When fetching multiple resources GET /resources/playlists when some of
"actions": [],
"episodes": [
{
"mediaItemUrl": "https://www.metalmondays.com/1.mp3",
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"mimeType": "audio/mpeg",
"name": "{eng}: The Wooden Boy",
},
{
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
"mimeType": "audio/mpeg",
"name": "{clc}: Down at the River",
},
],
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110501",
"name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`GET (fetch view models) When querying for a single View Model by ID GET /resources/audioItems/:id when the resource is published when an resource with the id is found should return the expected response 1`] = `
{
"actions": [],
"audioURL": "https://www.metalmondays.com/1.mp3",
"audioURL": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110110",
"lengthMilliseconds": 20000,
"mimeType": "audio/mpeg",
Expand Down Expand Up @@ -189,7 +189,7 @@ exports[`GET (fetch view models) When querying for a single View Model by ID GE
],
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 1",
"url": "https://www.metalmondays.com/1.mp3",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
}
`;

Expand Down Expand Up @@ -231,10 +231,15 @@ exports[`GET (fetch view models) When querying for a single View Model by ID GE
"actions": [],
"episodes": [
{
"mediaItemUrl": "https://www.metalmondays.com/1.mp3",
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
"mimeType": "audio/mpeg",
"name": "{eng}: The Wooden Boy",
},
{
"mediaItemUrl": "https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3",
"mimeType": "audio/mpeg",
"name": "{clc}: Down at the River",
},
],
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110501",
"name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ MediaItem {
"title": "episode title (in language)",
"titleEnglish": "Metal Mondays episode 1",
"type": "mediaItem",
"url": "https://www.metalmondays.com/1.mp3",
"url": "https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3",
}
`;

Expand Down Expand Up @@ -240,6 +240,12 @@ Playlist {
"type": "audioItem",
},
},
PlaylistItem {
"resourceCompositeIdentifier": {
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b110111",
"type": "audioItem",
},
},
],
"name": MultilingualText {
"items": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CommandInfoService } from '../../../app/controllers/command/services/co
import { DomainModelCtor } from '../../../lib/types/DomainModelCtor';
import { REPOSITORY_PROVIDER_TOKEN } from '../../../persistence/constants/persistenceConstants';
import { PlaylistViewModel } from '../../../view-models/buildViewModelForResource/viewModels';
import { AudioItem } from '../../models/audio-item/entities/audio-item.entity';
import BaseDomainModel from '../../models/BaseDomainModel';
import { AudioItem } from '../../models/audio-item/entities/audio-item.entity';
import { MediaItem } from '../../models/media-item/entities/media-item.entity';
import { Playlist } from '../../models/playlist';
import { validAggregateOrThrow } from '../../models/shared/functional';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/test-data/buildAudioItemTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const partialDtos: DTO<Omit<AudioItem, 'type'>>[] = [
text: buildSingleLanguageText(item.text, LanguageCode.English),
})),
},
mediaItemId: mediaItems[0].id,
mediaItemId: mediaItems[2].id,
lengthMilliseconds: 23409,
published: true,
},
Expand Down
18 changes: 17 additions & 1 deletion apps/api/src/test-data/buildMediaItemTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const dtos: DTO<MediaItem>[] = [
role: 'host',
},
],
url: 'https://www.metalmondays.com/1.mp3',
url: 'https://be.tsilhqotinlanguage.ca:3003/download?id=5671983.mp3',
lengthMilliseconds: 2500,
mimeType: MIMEType.mp3,
published: true,
Expand All @@ -37,6 +37,22 @@ const dtos: DTO<MediaItem>[] = [
published: true,
type: ResourceType.mediaItem,
},
{
id: '3',
title: 'episode title (in language)',
titleEnglish: 'Metal Mondays episode 2',
contributorAndRoles: [
{
contributorId: '2',
role: 'host',
},
],
url: 'https://be.tsilhqotinlanguage.ca:3003/download?id=5670051.mp3',
lengthMilliseconds: 2500,
mimeType: MIMEType.mp3,
published: true,
type: ResourceType.mediaItem,
},
];

export default () => dtos.map((dto) => new MediaItem(dto)).map(convertAggregatesIdToUuid);
6 changes: 6 additions & 0 deletions apps/api/src/test-data/buildPlaylistTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const partialDtos: Omit<DTO<Playlist>, 'type'>[] = [
id: AggregateId;
},
},
{
resourceCompositeIdentifier: audioItems[1].getCompositeIdentifier() as {
type: typeof ResourceType.audioItem;
id: AggregateId;
},
},
],
published: true,
},
Expand Down
11 changes: 11 additions & 0 deletions apps/coscrad-frontend/src/components/audio-panel/audio-panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MediaPlayer } from '@coscrad/media-player';

interface AudioPanelProps {
url: string;
}

const AudioPanel = ({ url }: AudioPanelProps): JSX.Element => {
return <MediaPlayer audioUrl={url} />;
};

export default AudioPanel;
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
import {
ICategorizableDetailQueryResult,
IPlaylistEpisode,
IPlayListViewModel,
ResourceType,
} from '@coscrad/api-interfaces';
import { Typography } from '@mui/material';
import { useState } from 'react';
import { ResourceDetailFullViewPresenter } from '../../../utils/generic-components/presenters/detail-views';
import { EpisodePresenter } from './episode-presenter';
import { HeadingLabel, IndexTable } from '../../../utils/generic-components/presenters/tables';
import { CellRenderersDefinition } from '../../../utils/generic-components/presenters/tables/generic-index-table-presenter/types/cell-renderers-definition';
import AudioPanel from '../../audio-panel/audio-panel';
import { renderAggregateUrlCell } from '../utils/render-audio-preview';

export const PlaylistDetailFullViewPresenter = ({
name,
id,
episodes,
}: ICategorizableDetailQueryResult<IPlayListViewModel>): JSX.Element => (
<ResourceDetailFullViewPresenter name={name} id={id} type={ResourceType.playlist}>
<Typography component={'div'}>
<Typography variant={'h5'}> Episodes </Typography>
{episodes.map((episode) => (
<EpisodePresenter episode={episode} />
))}
</Typography>
</ResourceDetailFullViewPresenter>
);
}: ICategorizableDetailQueryResult<IPlayListViewModel>): JSX.Element => {
const [url, setUrl] = useState<string | null>(null);

const headingLabels: HeadingLabel<IPlaylistEpisode>[] = [
{
propertyKey: 'name',
headingLabel: 'Name',
},
{
propertyKey: 'mediaItemUrl',
headingLabel: 'Audio',
},
];

const cellRenderers: CellRenderersDefinition<IPlaylistEpisode> = {
// TODO Consider making the name property `MultilingualText`
// name: ({ name }) => renderMultilingualTextCell(name),
mediaItemUrl: ({ mediaItemUrl }) =>
renderAggregateUrlCell(mediaItemUrl, (url: string) => setUrl(url)),
};

return (
<ResourceDetailFullViewPresenter name={name} id={id} type={ResourceType.playlist}>
<Typography component={'div'}>
<Typography variant={'h5'}> Episodes </Typography>
<IndexTable
headingLabels={headingLabels}
tableData={episodes}
cellRenderersDefinition={cellRenderers}
heading={'Episodes'}
filterableProperties={['name']}
/>
<AudioPanel url={url || ''} />
</Typography>
</ResourceDetailFullViewPresenter>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const PlaylistIndexPresenter = ({ entities: playlists }: PlaylistIndexSta
headingLabels={headingLabels}
tableData={playlists}
cellRenderersDefinition={cellRenderersDefinition}
heading={'Episodes'}
heading={'Playlists'}
filterableProperties={['episodes', 'name']}
matchers={matchers}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PlayArrowRounded } from '@mui/icons-material';
import { Button } from '@mui/material';

export const renderAggregateUrlCell = (url: string, handleClick: (url: string) => void) => (
<Button onClick={() => handleClick(url)}>
<PlayArrowRounded />
</Button>
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { IBaseViewModel } from '@coscrad/api-interfaces';

export const buildDefaultRenderer =
<T extends IBaseViewModel>(propertyKey: keyof T) =>
<T,>(propertyKey: keyof T) =>
(input: T) =>
<>{(JSON.stringify(input[propertyKey]) || '').replace(/"/g, '')}</>;
Loading

0 comments on commit 05c565d

Please sign in to comment.