diff --git a/components/CarPlay/Discover.tsx b/components/CarPlay/Discover.tsx index 135b0fb6..9449b4cf 100644 --- a/components/CarPlay/Discover.tsx +++ b/components/CarPlay/Discover.tsx @@ -1,11 +1,10 @@ import { ListTemplate } from 'react-native-carplay' import uuid from 'react-native-uuid' -const CarPlayDiscover = () => - new ListTemplate({ - id: uuid.v4(), - tabTitle: 'Discover', - tabSystemImageName: 'globe', - }) +const CarPlayDiscover = new ListTemplate({ + id: uuid.v4(), + tabTitle: 'Discover', + tabSystemImageName: 'globe', +}) export default CarPlayDiscover diff --git a/components/CarPlay/Home.tsx b/components/CarPlay/Home.tsx index 4b57f650..9a894c0b 100644 --- a/components/CarPlay/Home.tsx +++ b/components/CarPlay/Home.tsx @@ -7,45 +7,42 @@ import RecentTracksTemplate from './RecentTracks' import RecentArtistsTemplate from './RecentArtists' import uuid from 'react-native-uuid' -const CarPlayHome = () => - new ListTemplate({ - id: uuid.v4(), - title: 'Home', - tabTitle: 'Home', - tabSystemImageName: 'music.house.fill', - sections: [ - { - header: `Hi ${Client.user?.name ?? 'there'}`, - items: [ - { id: QueryKeys.RecentlyPlayedArtists, text: 'Recent Artists' }, - { id: QueryKeys.RecentlyPlayed, text: 'Recently Played' }, - { id: QueryKeys.UserPlaylists, text: 'Your Playlists' }, - ], - }, - ], - onItemSelect: async ({ index }) => { - console.debug(`Home item selected`) - - switch (index) { - case 0: { - const artists = - queryClient.getQueryData([ - QueryKeys.RecentlyPlayedArtists, - ]) ?? [] - CarPlay.pushTemplate(RecentArtistsTemplate(artists)) - break - } - case 1: { - const items = - queryClient.getQueryData([QueryKeys.RecentlyPlayed]) ?? [] - CarPlay.pushTemplate(RecentTracksTemplate(items)) - break - } - case 2: { - break - } - } +const CarPlayHome = new ListTemplate({ + id: uuid.v4(), + title: 'Home', + tabTitle: 'Home', + tabSystemImageName: 'music.house.fill', + sections: [ + { + header: `Hi ${Client.user?.name ?? 'there'}`, + items: [ + { id: QueryKeys.RecentlyPlayedArtists, text: 'Recent Artists' }, + { id: QueryKeys.RecentlyPlayed, text: 'Recently Played' }, + { id: QueryKeys.UserPlaylists, text: 'Your Playlists' }, + ], }, - }) + ], + onItemSelect: async ({ index }) => { + console.debug(`Home item selected`) + + switch (index) { + case 0: { + const artists = + queryClient.getQueryData([QueryKeys.RecentlyPlayedArtists]) ?? [] + CarPlay.pushTemplate(RecentArtistsTemplate(artists)) + break + } + case 1: { + const items = + queryClient.getQueryData([QueryKeys.RecentlyPlayed]) ?? [] + CarPlay.pushTemplate(RecentTracksTemplate(items)) + break + } + case 2: { + break + } + } + }, +}) export default CarPlayHome diff --git a/components/CarPlay/Navigation.tsx b/components/CarPlay/Navigation.tsx index c17b482d..06e5d8c2 100644 --- a/components/CarPlay/Navigation.tsx +++ b/components/CarPlay/Navigation.tsx @@ -3,12 +3,11 @@ import CarPlayHome from './Home' import CarPlayDiscover from './Discover' import uuid from 'react-native-uuid' -const CarPlayNavigation = () => - new TabBarTemplate({ - id: uuid.v4(), - title: 'Tabs', - templates: [CarPlayHome(), CarPlayDiscover()], - onTemplateSelect(template, e) {}, - }) +const CarPlayNavigation = new TabBarTemplate({ + id: uuid.v4(), + title: 'Tabs', + templates: [CarPlayHome, CarPlayDiscover], + onTemplateSelect(template, e) {}, +}) export default CarPlayNavigation diff --git a/components/CarPlay/NowPlaying.tsx b/components/CarPlay/NowPlaying.tsx index 70b7d02d..514efd80 100644 --- a/components/CarPlay/NowPlaying.tsx +++ b/components/CarPlay/NowPlaying.tsx @@ -1,9 +1,8 @@ import { NowPlayingTemplate } from 'react-native-carplay' import uuid from 'react-native-uuid' -const CarPlayNowPlaying = () => - new NowPlayingTemplate({ - id: uuid.v4(), - }) +const CarPlayNowPlaying = new NowPlayingTemplate({ + id: uuid.v4(), +}) export default CarPlayNowPlaying diff --git a/components/provider.tsx b/components/provider.tsx index 5a16dea4..dc4049c3 100644 --- a/components/provider.tsx +++ b/components/provider.tsx @@ -28,8 +28,8 @@ const JellifyContextInitializer = () => { setCarPlayConnected(true) if (loggedIn) { - CarPlay.setRootTemplate(CarPlayNavigation()) - // CarPlay.pushTemplate(CarPlayNowPlaying()) + CarPlay.setRootTemplate(CarPlayNavigation) + CarPlay.pushTemplate(CarPlayNowPlaying) if (Platform.OS === 'ios') { CarPlay.enableNowPlaying(true) // https://github.com/birkir/react-native-carplay/issues/185