Skip to content
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 23 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5223a16
extract shared code into DocumentModels
kkuepper Jan 24, 2024
7921634
refactor
kkuepper Jan 24, 2024
516f062
add empty pages for browse pages
kkuepper Jan 25, 2024
99863c0
Merge branch 'main' into feature/document-models
kkuepper Jan 25, 2024
bb70e9c
style chapter header
kkuepper Jan 25, 2024
afbbb5d
introduce DocumentList to be used by multiple pages
kkuepper Jan 25, 2024
88c4561
use SPA link instead of navigation to new site
kkuepper Jan 25, 2024
7b617e0
Merge commit 'dc210750660c9252a03bb81b526902ae2063e4b8' into feature/…
kkuepper Jan 29, 2024
a560307
review fixes
kkuepper Jan 29, 2024
714bdb5
update bmm-sdk to fix typing error
kkuepper Feb 1, 2024
a8c0e33
implement /featured route
kkuepper Feb 1, 2024
449ad12
use title from response
kkuepper Feb 1, 2024
f353b72
send UiLanguage as header
kkuepper Feb 1, 2024
9be0dc3
no longer send the language since the UiLanguage header takes care of…
kkuepper Feb 1, 2024
4fb6313
fix lint
kkuepper Feb 1, 2024
596e62d
review fixes
kkuepper Feb 2, 2024
c72d5dc
Reset changes in pnpm about vite
SimonSimCity Feb 2, 2024
1461129
remove typing
kkuepper Feb 2, 2024
0345896
Refactored `DocumentList` to just be a component and reused it
SimonSimCity Feb 2, 2024
6d721d5
Merged document-list and document-model - added note for empty list
SimonSimCity Feb 2, 2024
5403960
Fix reloading of api requests if language is changed
SimonSimCity Feb 2, 2024
0015771
Remove remaining console.log()
SimonSimCity Feb 2, 2024
2e2f536
Fixed linter
SimonSimCity Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions components/DocumentList.vue
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>

Check warning on line 181 in components/DocumentList.vue

View check run for this annotation

Codecov / codecov/patch

components/DocumentList.vue#L2-L181

Added lines #L2 - L181 were not covered by tests
28 changes: 28 additions & 0 deletions composables/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@
useLazyAsyncData("browse", () => new BrowseApi().browseGet()),
);
}

export function useBrowseEvents() {
return reactiveApi(
useLazyAsyncData("browse-events", () => new BrowseApi().browseEventsGet()),
);
}

export function useBrowseAudiobooks() {
return reactiveApi(
useLazyAsyncData("browse-audiobooks", () =>
new BrowseApi().browseAudiobooksGet(),
),
);
}

export function useBrowseMusic() {
return reactiveApi(
useLazyAsyncData("browse-music", () => new BrowseApi().browseMusicGet()),
);
}

export function useBrowsePodcast() {
return reactiveApi(
useLazyAsyncData("browse-podcast", () =>
new BrowseApi().browsePodcastsGet(),
),
);
}

Check warning on line 35 in composables/browse.ts

View check run for this annotation

Codecov / codecov/patch

composables/browse.ts#L8-L35

Added lines #L8 - L35 were not covered by tests
28 changes: 2 additions & 26 deletions composables/discover.ts
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";

Check warning on line 2 in composables/discover.ts

View check run for this annotation

Codecov / codecov/patch

composables/discover.ts#L2

Added line #L2 was not covered by tests

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),

Check warning on line 7 in composables/discover.ts

View check run for this annotation

Codecov / codecov/patch

composables/discover.ts#L7

Added line #L7 was not covered by tests
),
);
}
8 changes: 8 additions & 0 deletions composables/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@
useLazyAsyncData("playlists", () => new PlaylistApi().playlistGet()),
);
}

export function useFeaturedPlaylists() {
return reactiveApi(
useLazyAsyncData("playlists-featured", () =>
new PlaylistApi().playlistDocumentsGet(),
),
);
}

Check warning on line 45 in composables/playlist.ts

View check run for this annotation

Codecov / codecov/patch

composables/playlist.ts#L38-L45

Added lines #L38 - L45 were not covered by tests
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@auth0/auth0-vue": "^2.3.3",
"@bcc-code/bmm-sdk-fetch": "^7.1.0",
"@bcc-code/bmm-sdk-fetch": "^7.3.0",
"@headlessui/vue": "^1.7.17",
"@microsoft/applicationinsights-web": "^3.0.7",
"@pinia/nuxt": "^0.5.1",
Expand Down
8 changes: 8 additions & 0 deletions pages/browse/audiobooks.vue
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>

Check warning on line 8 in pages/browse/audiobooks.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/audiobooks.vue#L2-L8

Added lines #L2 - L8 were not covered by tests
8 changes: 8 additions & 0 deletions pages/browse/events.vue
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>

Check warning on line 8 in pages/browse/events.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/events.vue#L2-L8

Added lines #L2 - L8 were not covered by tests
46 changes: 2 additions & 44 deletions pages/browse/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,9 @@
const { t } = useI18n();
toolbarTitleStore().setReactiveToolbarTitle(() => t("nav.browse"));

const { data: browseSections, pending } = useBrowse();
const { data: models, pending } = useBrowse();

Check warning on line 5 in pages/browse/index.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/index.vue#L5

Added line #L5 was not covered by tests
</script>

<template>
<div>
<PageHeading class="mb-6">{{ $t("nav.browse") }}</PageHeading>
<template v-if="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>
<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>
</div>
<DocumentList :items="models" :pending="pending"></DocumentList>

Check warning on line 9 in pages/browse/index.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/index.vue#L9

Added line #L9 was not covered by tests
</template>
7 changes: 6 additions & 1 deletion pages/browse/music.vue
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>

Check warning on line 5 in pages/browse/music.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/music.vue#L2-L5

Added lines #L2 - L5 were not covered by tests
<template>
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1>
<DocumentList :items="models?.items" :pending="pending"></DocumentList>

Check warning on line 7 in pages/browse/music.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/music.vue#L7

Added line #L7 was not covered by tests
</template>
7 changes: 6 additions & 1 deletion pages/browse/podcasts.vue
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>

Check warning on line 5 in pages/browse/podcasts.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/podcasts.vue#L2-L5

Added lines #L2 - L5 were not covered by tests
<template>
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1>
<DocumentList :items="models?.items" :pending="pending"></DocumentList>

Check warning on line 7 in pages/browse/podcasts.vue

View check run for this annotation

Codecov / codecov/patch

pages/browse/podcasts.vue#L7

Added line #L7 was not covered by tests
</template>
7 changes: 6 additions & 1 deletion pages/featured.vue
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>

Check warning on line 5 in pages/featured.vue

View check run for this annotation

Codecov / codecov/patch

pages/featured.vue#L2-L5

Added lines #L2 - L5 were not covered by tests
<template>
<h1>The route {{ useRoute().name }} has not been implemented yet.</h1>
<DocumentList :items="models?.items" :pending="pending"></DocumentList>

Check warning on line 7 in pages/featured.vue

View check run for this annotation

Codecov / codecov/patch

pages/featured.vue#L7

Added line #L7 was not covered by tests
</template>
Loading
Loading