Skip to content

Commit

Permalink
Update title when changing sections in navigation
Browse files Browse the repository at this point in the history
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
  • Loading branch information
JuliaKirschenheuter committed Jan 10, 2023
1 parent 8d361fc commit dc82656
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-public.js.map

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const Timeline = () => import('../views/Timeline')
const Faces = () => import('../views/Faces')
const FaceContent = () => import('../views/FaceContent')

const baseTitle = document.title

Vue.use(Router)

let mapsPath = generateUrl('/apps/maps')
Expand Down Expand Up @@ -74,6 +76,11 @@ const router = new Router({
props: route => ({
rootTitle: t('photos', 'All your media'),
}),
meta: {
rootTitle: () => {
return t('photos', 'All your media')
},
},
},
{
path: '/photos',
Expand All @@ -83,6 +90,11 @@ const router = new Router({
rootTitle: t('photos', 'Photos'),
mimesType: imageMimes,
}),
meta: {
rootTitle: () => {
return t('photos', 'Photos')
},
},
},
{
path: '/videos',
Expand All @@ -92,11 +104,21 @@ const router = new Router({
rootTitle: t('photos', 'Videos'),
mimesType: videoMimes,
}),
meta: {
rootTitle: () => {
return t('photos', 'Videos')
},
},
},
{
path: '/albums',
component: Albums,
name: 'albums',
meta: {
rootTitle: () => {
return t('photos', 'Albums')
},
},
},
{
path: '/albums/:albumName*',
Expand All @@ -105,11 +127,21 @@ const router = new Router({
props: route => ({
albumName: route.params.albumName,
}),
meta: {
rootTitle: (to) => {
return t('photos', 'Album {title}', { title: to.params.albumName })
},
},
},
{
path: '/sharedalbums',
component: SharedAlbums,
name: 'sharedAlbums',
meta: {
rootTitle: () => {
return t('photos', 'Shared Albums')
},
},
},
{
path: '/sharedalbums/:albumName*',
Expand All @@ -118,6 +150,11 @@ const router = new Router({
props: route => ({
albumName: route.params.albumName,
}),
meta: {
rootTitle: (to) => {
return t('photos', 'Shared album {title}', { title: to.params.albumName })
},
},
},
{
path: '/public/:token',
Expand All @@ -126,6 +163,11 @@ const router = new Router({
props: route => ({
token: route.params.token,
}),
meta: {
rootTitle: (to) => {
return t('photos', 'Public album {title}', { title: to.params.token })
},
},
},
{
path: '/folders/:path*',
Expand All @@ -137,6 +179,11 @@ const router = new Router({
isRoot: !route.params.path,
rootTitle: t('photos', 'Folders'),
}),
meta: {
rootTitle: () => {
return t('photos', 'Folders')
},
},
},
{
path: '/shared/:path*',
Expand All @@ -149,6 +196,11 @@ const router = new Router({
rootTitle: t('photos', 'Shared with you'),
showShared: true,
}),
meta: {
rootTitle: () => {
return t('photos', 'Shared with you')
},
},
},
{
path: '/favorites',
Expand All @@ -158,6 +210,11 @@ const router = new Router({
rootTitle: t('photos', 'Favorites'),
onlyFavorites: true,
}),
meta: {
rootTitle: () => {
return t('photos', 'Favorites')
},
},
},
{
path: '/tags/',
Expand All @@ -169,6 +226,11 @@ const router = new Router({
isRoot: !route.params.path,
rootTitle: t('photos', 'Tagged photos'),
}),
meta: {
rootTitle: () => {
return t('photos', 'Tagged photos')
},
},
},
{
path: '/tags/:path',
Expand All @@ -178,6 +240,11 @@ const router = new Router({
props: route => ({
path: `${route.params.path ? route.params.path : ''}`,
}),
meta: {
rootTitle: (to) => {
return t('photos', 'Tagged photo {title}', { title: to.params.path })
},
},
},
{
path: '/maps',
Expand All @@ -195,6 +262,11 @@ const router = new Router({
rootTitle: t('photos', 'On this day'),
onThisDay: true,
}),
meta: {
rootTitle: () => {
return t('photos', 'On this day')
},
},
},
{
path: '/faces',
Expand All @@ -215,8 +287,23 @@ const router = new Router({
rootTitle: route.params.faceName,
faceName: route.params.faceName,
}),
meta: {
rootTitle: (to) => {
return t('photos', "{title}'s face", { title: to.params.rootTitle })
},
},
},
],
})

router.afterEach((to) => {
const rootTitle = to.meta.rootTitle?.(to)

if (rootTitle) {
document.title = `${rootTitle} - ${baseTitle}`
} else {
document.title = baseTitle
}
})

export default router

0 comments on commit dc82656

Please sign in to comment.