Skip to content

Commit

Permalink
Make landing page configurable (#4200)
Browse files Browse the repository at this point in the history
* Implement customizable landing pages

* Implement curated list for default landing page dropdown options

* Update top nav link to redirect back to selected landing page

* Update top nav title to be 'Go to {page}' for improved clarity

* Remove landing page from selection and/or restore selection to default if is no longer valid
  • Loading branch information
kommunarr authored Nov 20, 2023
1 parent e7310bd commit 58fe474
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 44 deletions.
14 changes: 12 additions & 2 deletions src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export default defineComponent({
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
},

landingPage: function() {
return '/' + this.$store.getters.getLandingPage
},

externalLinkOpeningPromptNames: function () {
return [
this.$t('Yes'),
Expand All @@ -133,7 +137,7 @@ export default defineComponent({
$route () {
// react to route changes...
// Hide top nav filter panel on page change
this.$refs.topNav.hideFilters()
this.$refs.topNav?.hideFilters()
}
},
created () {
Expand Down Expand Up @@ -175,7 +179,13 @@ export default defineComponent({
})

this.$router.afterEach((to, from) => {
this.$refs.topNav.navigateHistory()
this.$refs.topNav?.navigateHistory()
})

this.$router.onReady(() => {
if (this.$router.currentRoute.path !== this.landingPage && this.landingPage !== '/subscriptions') {
this.$router.push({ path: this.landingPage })
}
})
})
},
Expand Down
51 changes: 37 additions & 14 deletions src/renderer/components/general-settings/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ export default defineComponent({
'invidious',
'local'
],
defaultPageNames: [
'Subscriptions',
'Trending',
'Most Popular',
'Playlists',
'History'
],
defaultPageValues: [
'subscriptions',
'trending',
'mostPopular',
'playlists',
'history'
],
viewTypeValues: [
'grid',
'list'
Expand All @@ -57,6 +43,15 @@ export default defineComponent({
'',
'openLinkAfterPrompt',
'doNothing'
],
includedDefaultPageNames: [
'subscriptions',
'subscribedChannels',
'trending',
'popular',
'userPlaylists',
'history',
'settings'
]
}
},
Expand All @@ -79,10 +74,38 @@ export default defineComponent({
checkForBlogPosts: function () {
return this.$store.getters.getCheckForBlogPosts
},
hidePlaylists: function () {
return this.$store.getters.getHidePlaylists
},
hidePopularVideos: function () {
return this.$store.getters.getHidePopularVideos
},
hideTrendingVideos: function () {
return this.$store.getters.getHideTrendingVideos
},
defaultPages: function () {
let includedPageNames = this.includedDefaultPageNames
if (this.hideTrendingVideos) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'trending')
if (this.hidePlaylists) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'userPlaylists')
if (!(!this.hidePopularVideos && (this.backendFallback || this.backendPreference === 'invidious'))) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'popular')
return this.$router.getRoutes().filter((route) => includedPageNames.includes(route.name))
},
defaultPageNames: function () {
return this.defaultPages.map((route) => this.$t(route.meta.title))
},
defaultPageValues: function () {
// avoid Vue parsing issues by excluding '/' from path values
return this.defaultPages.map((route) => route.path.substring(1))
},
backendPreference: function () {
return this.$store.getters.getBackendPreference
},
landingPage: function () {
const landingPage = this.$store.getters.getLandingPage
// invalidate landing page selection & restore to default value if no longer valid
if (!this.defaultPageValues.includes(landingPage)) {
this.updateLandingPage('subscriptions')
}
return this.$store.getters.getLandingPage
},
region: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
@change="handlePreferredApiBackend"
/>
<ft-select
v-if="false"
:placeholder="$t('Settings.General Settings.Default Landing Page')"
:value="landingPage"
:select-names="defaultPageNames"
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export default defineComponent({
return this.$store.getters.getHideHeaderLogo
},

landingPage: function () {
return this.$store.getters.getLandingPage
},

headerLogoTitle: function () {
return this.$t('Go to page',
{
page: this.$t(this.$router.getRoutes()
.find((route) => route.path === '/' + this.landingPage)
.meta.title
)
})
},

enableSearchSuggestions: function () {
return this.$store.getters.getEnableSearchSuggestions
},
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/top-nav/top-nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
dir="ltr"
role="link"
tabindex="0"
:title="$t('Subscriptions.Subscriptions')"
@click="navigate('subscriptions')"
@keydown.space.prevent="navigate('subscriptions')"
@keydown.enter.prevent="navigate('subscriptions')"
:title="headerLogoTitle"
@click="navigate(landingPage)"
@keydown.space.prevent="navigate(landingPage)"
@keydown.enter.prevent="navigate(landingPage)"
>
<div
class="logoIcon"
Expand Down
55 changes: 32 additions & 23 deletions src/renderer/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,47 @@ const router = new Router({
routes: [
{
path: '/',
name: 'default',
meta: {
title: 'Subscriptions.Subscriptions'
},
component: Subscriptions
},
{
path: '/subscriptions',
name: 'subscriptions',
meta: {
title: 'Subscriptions.Subscriptions'
},
component: Subscriptions
},
{
path: '/subscribedchannels',
name: 'subscribedChannels',
meta: {
title: 'Channels.Title'
},
component: SubscribedChannels
},
{
path: '/settings/profile',
meta: {
title: 'Profile.Profile Settings'
},
component: ProfileSettings
},
{
path: '/settings/profile/new',
name: 'newProfile',
meta: {
title: 'Profile.Create New Profile'
},
component: ProfileEdit
},
{
path: '/settings/profile/edit/:id',
name: 'editProfile',
meta: {
title: 'Profile.Edit Profile'
},
component: ProfileEdit
},
{
path: '/trending',
name: 'trending',
meta: {
title: 'Trending.Trending'
},
component: Trending
},
{
path: '/popular',
name: 'popular',
meta: {
title: 'Most Popular'
},
component: Popular
},
{
path: '/userplaylists',
name: 'userPlaylists',
meta: {
title: 'User Playlists.Your Playlists'
},
Expand All @@ -95,18 +78,44 @@ const router = new Router({
},
{
path: '/settings',
name: 'settings',
meta: {
title: 'Settings.Settings'
},
component: Settings
},
{
path: '/about',
name: 'about',
meta: {
title: 'About.About'
},
component: About
},
{
path: '/settings/profile',
name: 'profileSettings',
meta: {
title: 'Profile.Profile Settings'
},
component: ProfileSettings
},
{
path: '/settings/profile/new',
name: 'newProfile',
meta: {
title: 'Profile.Create New Profile'
},
component: ProfileEdit
},
{
path: '/settings/profile/edit/:id',
name: 'editProfile',
meta: {
title: 'Profile.Edit Profile'
},
component: ProfileEdit
},
{
path: '/search/:query',
meta: {
Expand Down
1 change: 1 addition & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Close: Close
Back: Back
Forward: Forward
Open New Window: Open New Window
Go to page: Go to {page}

Version {versionNumber} is now available! Click for more details: Version {versionNumber} is now available! Click
for more details
Expand Down

0 comments on commit 58fe474

Please sign in to comment.