-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extract shared code into DocumentList #275
Merged
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5223a16
extract shared code into DocumentModels
kkuepper 7921634
refactor
kkuepper 516f062
add empty pages for browse pages
kkuepper 99863c0
Merge branch 'main' into feature/document-models
kkuepper bb70e9c
style chapter header
kkuepper afbbb5d
introduce DocumentList to be used by multiple pages
kkuepper 88c4561
use SPA link instead of navigation to new site
kkuepper 7b617e0
Merge commit 'dc210750660c9252a03bb81b526902ae2063e4b8' into feature/…
kkuepper a560307
review fixes
kkuepper 714bdb5
update bmm-sdk to fix typing error
kkuepper a8c0e33
implement /featured route
kkuepper 449ad12
use title from response
kkuepper f353b72
send UiLanguage as header
kkuepper 9be0dc3
no longer send the language since the UiLanguage header takes care of…
kkuepper 4fb6313
fix lint
kkuepper 596e62d
review fixes
kkuepper c72d5dc
Reset changes in pnpm about vite
SimonSimCity 1461129
remove typing
kkuepper 0345896
Refactored `DocumentList` to just be a component and reused it
SimonSimCity 6d721d5
Merged document-list and document-model - added note for empty list
SimonSimCity 5403960
Fix reloading of api requests if language is changed
SimonSimCity 0015771
Remove remaining console.log()
SimonSimCity 2e2f536
Fixed linter
SimonSimCity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,36 @@ | ||
<script setup lang="ts"> | ||
import type { DocumentListIAllDocumentModels } from "@bcc-code/bmm-sdk-fetch"; | ||
|
||
const props = defineProps<{ | ||
list: DocumentListIAllDocumentModels | null; | ||
pending: boolean; | ||
}>(); | ||
|
||
watch( | ||
props, | ||
() => { | ||
toolbarTitleStore().setToolbarTitle(props.list?.title ?? " "); | ||
}, | ||
{ immediate: true }, | ||
); | ||
</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> | ||
<DocumentModels | ||
v-if="list && list.items" | ||
:models="list.items" | ||
></DocumentModels> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<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<{ | ||
models: IAllDocumentModels[]; | ||
}>(); | ||
|
||
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); | ||
kkuepper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return url.pathname + url.search + url.hash; | ||
}; | ||
|
||
const breakpoints = useBreakpoints(breakpointsTailwind); | ||
const isSmallScreen = breakpoints.smallerOrEqual("lg"); | ||
</script> | ||
|
||
<template> | ||
<template | ||
v-for="group in convertModels(props.models)" | ||
: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 ... | ||
{{ console.log("not implemented", item) }} | ||
</div> | ||
</li> | ||
</template> | ||
</ol> | ||
</template> | ||
</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,7 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseAudiobooks(); | ||
</script> | ||
|
||
<template> | ||
<DocumentList :list="models" :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,7 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseEvents(); | ||
</script> | ||
|
||
<template> | ||
<DocumentList :list="models" :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 |
---|---|---|
|
@@ -2,12 +2,11 @@ | |
const { t } = useI18n(); | ||
toolbarTitleStore().setReactiveToolbarTitle(() => t("nav.browse")); | ||
|
||
const { data: browseSections, pending } = useBrowse(); | ||
const { data: models, pending } = useBrowse(); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<PageHeading class="mb-6">{{ $t("nav.browse") }}</PageHeading> | ||
<template v-if="pending"> | ||
<ul> | ||
<li | ||
|
@@ -17,36 +16,8 @@ const { data: browseSections, pending } = useBrowse(); | |
></li> | ||
</ul> | ||
</template> | ||
<ul v-else> | ||
<template v-for="section in browseSections" :key="section.id || 0"> | ||
<PageHeading v-if="section.type === 'section_header'" :level="3"> | ||
<div class="flex items-center justify-between"> | ||
<div> | ||
<a v-if="typeof section.link === 'string'" :href="section.link"> | ||
{{ section.title }} | ||
</a> | ||
<span v-else>{{ section.title }}</span> | ||
</div> | ||
<a v-if="section.link" :href="section.link"> | ||
<ButtonStyled intent="secondary" size="small"> | ||
<span class="whitespace-nowrap"> | ||
{{ t("home.list.see-all") }} | ||
</span> | ||
</ButtonStyled> | ||
</a> | ||
</div> | ||
</PageHeading> | ||
<AlbumItem v-else-if="section.type === 'album'" :album="section" /> | ||
<PlaylistItem | ||
v-else-if="section.type === 'playlist'" | ||
:playlist="section" | ||
/> | ||
<PodcastItem | ||
v-else-if="section.type === 'podcast'" | ||
:podcast="section" | ||
/> | ||
<p v-else style="color: red">This is not implemented yet</p> | ||
</template> | ||
</ul> | ||
<template v-else> | ||
<DocumentModels v-if="models !== null" :models="models"></DocumentModels> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the question |
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowseMusic(); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList :list="models" :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,7 @@ | ||
<script lang="ts" setup> | ||
const { data: models, pending } = useBrowsePodcast(); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList :list="models" :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,12 @@ | ||
<script lang="ts" setup> | ||
import type { DocumentListIAllDocumentModels } from "@bcc-code/bmm-sdk-fetch"; | ||
|
||
const { data: models, pending } = useFeaturedPlaylists(); | ||
</script> | ||
|
||
<template> | ||
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1> | ||
<DocumentList | ||
:list="models as DocumentListIAllDocumentModels" | ||
kkuepper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:pending="pending" | ||
></DocumentList> | ||
</template> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all pages who use this for listing set the title here? My suggestion is that the title should rather be handled by the page than by a component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean. If the server returns a DocumentList it also provides the title.
To make it obvious on the page that the title will be set, I could create a method SetTitleFromDocumentList() or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... I'd rather put these lines into each page... For me, the title is a part of the page and should not be controlled by a component. By this, you can use this component at more pages, also on one page multiple times.