-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from bcc-code/feature/document-models
extract shared code into DocumentList
- Loading branch information
Showing
18 changed files
with
290 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<script setup lang="ts"> | ||
import type { | ||
IAllDocumentModels, | ||
TrackModel, | ||
SectionHeaderModel, | ||
} from "@bcc-code/bmm-sdk-fetch"; | ||
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"; | ||
type IDiscoverableGroup = { | ||
header: SectionHeaderModel | null; | ||
items: Exclude<IAllDocumentModels, SectionHeaderModel>[]; | ||
}; | ||
const { t } = useI18n(); | ||
const props = defineProps<{ | ||
items: IAllDocumentModels[] | null | undefined; | ||
pending: boolean; | ||
}>(); | ||
const convertModels = (models: IAllDocumentModels[]) => { | ||
let currentSection: IDiscoverableGroup["items"] = []; | ||
const result: IDiscoverableGroup[] = []; | ||
models.forEach((el, i) => { | ||
if (el.type === "section_header") { | ||
currentSection = []; | ||
result.push({ | ||
header: el, | ||
items: currentSection, | ||
}); | ||
} else if (i === 0) { | ||
currentSection = [el]; | ||
result.push({ | ||
header: null, | ||
items: currentSection, | ||
}); | ||
} else { | ||
currentSection.push(el); | ||
} | ||
}); | ||
return result; | ||
}; | ||
const { setQueue } = useNuxtApp().$mediaPlayer; | ||
const playItem = (item: TrackModel, group: IDiscoverableGroup) => { | ||
const items = group.items.filter((c): c is TrackModel => c.type === "track"); | ||
setQueue( | ||
items, | ||
items.findIndex((track) => track.id === item.id), | ||
); | ||
}; | ||
// We remove the hostname so that we use SPA links (without full page refresh) | ||
const parseLink = (link: string) => { | ||
const url = new URL(link); | ||
return url.pathname + url.search + url.hash; | ||
}; | ||
const breakpoints = useBreakpoints(breakpointsTailwind); | ||
const isSmallScreen = breakpoints.smallerOrEqual("lg"); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<template v-if="props.pending"> | ||
<ul> | ||
<li | ||
v-for="index in 5" | ||
:key="index" | ||
class="my-6 h-11 w-full animate-pulse rounded-lg bg-background-2" | ||
></li> | ||
</ul> | ||
</template> | ||
<template v-else-if="props.items" | ||
><template | ||
v-for="group in convertModels(props.items)" | ||
:key="group.header?.id || 0" | ||
> | ||
<PageHeading v-if="group.header" :level="3"> | ||
<div class="flex items-center justify-between"> | ||
<div> | ||
<NuxtLink | ||
v-if="typeof group.header.link === 'string'" | ||
:to="parseLink(group.header.link)" | ||
> | ||
{{ group.header.title }} | ||
</NuxtLink> | ||
<span v-else>{{ group.header.title }}</span> | ||
</div> | ||
<NuxtLink | ||
v-if="group.header.link" | ||
:to="parseLink(group.header.link)" | ||
> | ||
<ButtonStyled intent="secondary" size="small"> | ||
<span class="whitespace-nowrap"> | ||
{{ t("home.list.see-all") }} | ||
</span> | ||
</ButtonStyled> | ||
</NuxtLink> | ||
</div> | ||
</PageHeading> | ||
<div | ||
v-if="group.header?.useCoverCarousel" | ||
class="flex flex-row flex-wrap gap-6" | ||
> | ||
<template | ||
v-for="item in group.items.slice(0, isSmallScreen ? 4 : 6)" | ||
:key="item.id" | ||
> | ||
<NuxtLink | ||
v-if="item.type === 'album'" | ||
:to="{ name: 'album-id', params: { id: item.id } }" | ||
> | ||
<ItemCard :item="item" /> | ||
</NuxtLink> | ||
<NuxtLink | ||
v-else-if="item.type === 'playlist'" | ||
:to="{ name: 'playlist-curated-id', params: { id: item.id } }" | ||
> | ||
<ItemCard :item="item" /> | ||
</NuxtLink> | ||
<NuxtLink | ||
v-else-if="item.type === 'podcast'" | ||
:to="{ name: 'playlist-podcast-id', params: { id: item.id } }" | ||
> | ||
<ItemCard :item="item" /> | ||
</NuxtLink> | ||
<div | ||
v-else | ||
class="grid w-52 flex-shrink-0 basis-52 gap-4" | ||
style="background-color: rgba(255, 0, 0, 0.4); color: red" | ||
> | ||
"{{ item.type }}" is not yet implemented ... | ||
</div> | ||
</template> | ||
</div> | ||
<ol | ||
v-else | ||
class="w-full divide-y divide-label-separator grid grid-cols-tracklist" | ||
> | ||
<template v-for="item in group.items" :key="item.id"> | ||
<h2 | ||
v-if="item.type === 'chapter_header'" | ||
class="text-2xl font-extrabold pt-10 pb-4" | ||
> | ||
{{ item.title }} | ||
</h2> | ||
<TrackItem | ||
v-else-if="item.type === 'track'" | ||
:track="item" | ||
:is-track-type-known="true" | ||
show-thumbnail | ||
@play-track="playItem(item, group)" | ||
></TrackItem> | ||
<ContributorListItem | ||
v-else-if="item.type === 'contributor'" | ||
:contributor="item" | ||
></ContributorListItem> | ||
<AlbumItem v-else-if="item.type === 'album'" :album="item" /> | ||
<PlaylistItem | ||
v-else-if="item.type === 'playlist'" | ||
:playlist="item" | ||
/> | ||
<PodcastItem v-else-if="item.type === 'podcast'" :podcast="item" /> | ||
<li v-else> | ||
<div style="background-color: rgba(255, 0, 0, 0.4); color: red"> | ||
"{{ item.type }}" is not yet implemented ... | ||
</div> | ||
</li> | ||
</template> | ||
</ol> | ||
</template> | ||
</template> | ||
<template v-else> | ||
<div style="background-color: rgba(255, 0, 0, 0.4); color: red"> | ||
This list is empty 😔 | ||
</div> | ||
</template> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,10 @@ | ||
import { DiscoverApi } from "@bcc-code/bmm-sdk-fetch"; | ||
import type { | ||
DiscoverGetRequest, | ||
SectionHeaderModel, | ||
IAllDocumentModels, | ||
} from "@bcc-code/bmm-sdk-fetch"; | ||
|
||
export type IDiscoverableGroup = { | ||
header: SectionHeaderModel | null; | ||
items: Exclude<IAllDocumentModels, SectionHeaderModel>[]; | ||
}; | ||
import type { DiscoverGetRequest } from "@bcc-code/bmm-sdk-fetch"; | ||
|
||
export function useDiscover(requestParameters: DiscoverGetRequest) { | ||
return reactiveApi( | ||
useLazyAsyncData("discover", () => | ||
new DiscoverApi().discoverGet(requestParameters).then((d) => { | ||
let currentSection: IDiscoverableGroup["items"] = []; | ||
const result: IDiscoverableGroup[] = []; | ||
d.forEach((el) => { | ||
if (el.type === "section_header") { | ||
currentSection = []; | ||
result.push({ | ||
header: el, | ||
items: currentSection, | ||
}); | ||
} else { | ||
currentSection.push(el); | ||
} | ||
}); | ||
return result; | ||
}), | ||
new DiscoverApi().discoverGet(requestParameters), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseAudiobooks(); | ||
setTitleOfDocumentList(models); | ||
</script> | ||
|
||
<template> | ||
<DocumentList :items="models?.items" :pending="pending"></DocumentList> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseEvents(); | ||
setTitleOfDocumentList(models); | ||
</script> | ||
|
||
<template> | ||
<DocumentList :items="models?.items" :pending="pending"></DocumentList> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseMusic(); | ||
setTitleOfDocumentList(models); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList :items="models?.items" :pending="pending"></DocumentList> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowsePodcast(); | ||
setTitleOfDocumentList(models); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList :items="models?.items" :pending="pending"></DocumentList> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useFeaturedPlaylists(); | ||
setTitleOfDocumentList(models); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList :items="models?.items" :pending="pending"></DocumentList> | ||
</template> |
Oops, something went wrong.