Browse Source

fix(web): redirect to parent folder if asset viewer was open before reload (#2863)

* fix(web): redirect to parent folder if asset viewer was open before reload

* chore(web): use route constants in all routes
Sophie 2 years ago
parent
commit
c404ea20ee

+ 1 - 0
web/src/lib/constants.ts

@@ -18,6 +18,7 @@ export enum AppRoute {
 	SEARCH = '/search',
 	MAP = '/map',
 	USER_SETTINGS = '/user-settings',
+	MEMORY = '/memory',
 
 	AUTH_LOGIN = '/auth/login',
 	AUTH_LOGOUT = '/auth/logout',

+ 4 - 3
web/src/routes/(user)/albums/[albumId]/photos/[assetId]/+page.ts

@@ -1,18 +1,19 @@
 import { redirect } from '@sveltejs/kit';
 export const prerender = false;
 import type { PageLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageLoad = async ({ params, parent }) => {
 	const { user } = await parent();
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	const albumId = params['albumId'];
 
 	if (albumId) {
-		throw redirect(302, `/albums/${albumId}`);
+		throw redirect(302, `${AppRoute.ALBUMS}/${albumId}`);
 	} else {
-		throw redirect(302, `/photos`);
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 };

+ 0 - 0
web/src/routes/(user)/archive/photos/[assetId]/+page.svelte


+ 13 - 0
web/src/routes/(user)/archive/photos/[assetId]/+page.ts

@@ -0,0 +1,13 @@
+import { redirect } from '@sveltejs/kit';
+export const prerender = false;
+import type { PageLoad } from './$types';
+import { AppRoute } from '$lib/constants';
+
+export const load: PageLoad = async ({ parent }) => {
+	const { user } = await parent();
+	if (!user) {
+		throw redirect(302, AppRoute.AUTH_LOGIN);
+	}
+
+	throw redirect(302, AppRoute.ARCHIVE);
+};

+ 2 - 1
web/src/routes/(user)/explore/+page.server.ts

@@ -1,10 +1,11 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ locals, parent }) => {
 	const { user } = await parent();
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	const { data: items } = await locals.api.searchApi.getExploreData();

+ 3 - 2
web/src/routes/(user)/favorites/[assetId]/+page.server.ts

@@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
 export const prerender = false;
 
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else {
-		throw redirect(302, '/favorites');
+		throw redirect(302, AppRoute.FAVORITES);
 	}
 };

+ 3 - 2
web/src/routes/(user)/memory/photos/+page.server.ts

@@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
 export const prerender = false;
 
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else {
-		throw redirect(302, '/memory');
+		throw redirect(302, AppRoute.MEMORY);
 	}
 };

+ 3 - 2
web/src/routes/(user)/memory/photos/[assetId]/+page.server.ts

@@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
 export const prerender = false;
 
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else {
-		throw redirect(302, '/memory');
+		throw redirect(302, AppRoute.MEMORY);
 	}
 };

+ 2 - 1
web/src/routes/(user)/people/+page.server.ts

@@ -1,10 +1,11 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ locals, parent }) => {
 	const { user } = await parent();
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	const { data: people } = await locals.api.personApi.getAllPeople();

+ 2 - 1
web/src/routes/(user)/people/[personId]/+page.server.ts

@@ -1,10 +1,11 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ locals, parent, params }) => {
 	const { user } = await parent();
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	const { data: person } = await locals.api.personApi.getPerson({ id: params.personId });

+ 0 - 0
web/src/routes/(user)/people/[personId]/photos/[assetId]/+page.svelte


+ 14 - 0
web/src/routes/(user)/people/[personId]/photos/[assetId]/+page.ts

@@ -0,0 +1,14 @@
+import { redirect } from '@sveltejs/kit';
+export const prerender = false;
+import type { PageLoad } from './$types';
+import { AppRoute } from '$lib/constants';
+
+export const load: PageLoad = async ({ params, parent }) => {
+	const { user } = await parent();
+	if (!user) {
+		throw redirect(302, AppRoute.AUTH_LOGIN);
+	}
+
+	const personId = params['personId'];
+	throw redirect(302, `${AppRoute.PEOPLE}/${personId}`);
+};

+ 3 - 2
web/src/routes/(user)/photos/[assetId]/+page.server.ts

@@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
 export const prerender = false;
 
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 };

+ 2 - 1
web/src/routes/(user)/search/+page.server.ts

@@ -1,10 +1,11 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ locals, parent, url }) => {
 	const { user } = await parent();
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	const term = url.searchParams.get('q') || url.searchParams.get('query') || undefined;

+ 0 - 0
web/src/routes/(user)/search/photos/[assetId]/+page.svelte


+ 13 - 0
web/src/routes/(user)/search/photos/[assetId]/+page.ts

@@ -0,0 +1,13 @@
+import { redirect } from '@sveltejs/kit';
+export const prerender = false;
+import type { PageLoad } from './$types';
+import { AppRoute } from '$lib/constants';
+
+export const load: PageLoad = async ({ parent }) => {
+	const { user } = await parent();
+	if (!user) {
+		throw redirect(302, AppRoute.AUTH_LOGIN);
+	}
+
+	throw redirect(302, AppRoute.SEARCH);
+};

+ 3 - 2
web/src/routes/+page.server.ts

@@ -2,18 +2,19 @@ export const prerender = false;
 
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ parent, locals: { api } }) => {
 	const { user } = await parent();
 	if (user) {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 
 	const { data } = await api.userApi.getUserCount({ admin: true });
 
 	if (data.userCount > 0) {
 		// Redirect to login page if an admin is already registered.
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	return {

+ 4 - 3
web/src/routes/admin/+page.server.ts

@@ -1,14 +1,15 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else if (!user.isAdmin) {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 
-	throw redirect(302, '/admin/user-management');
+	throw redirect(302, AppRoute.ADMIN_USER_MANAGEMENT);
 };

+ 3 - 2
web/src/routes/admin/server-status/+page.server.ts

@@ -1,13 +1,14 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ parent, locals: { api } }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else if (!user.isAdmin) {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 
 	const { data: stats } = await api.serverInfoApi.getStats();

+ 3 - 2
web/src/routes/admin/system-settings/+page.server.ts

@@ -1,13 +1,14 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load: PageServerLoad = async ({ parent }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else if (!user.isAdmin) {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 
 	return {

+ 3 - 2
web/src/routes/admin/user-management/+page.server.ts

@@ -1,13 +1,14 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ parent, locals: { api } }) => {
 	const { user } = await parent();
 
 	if (!user) {
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	} else if (!user.isAdmin) {
-		throw redirect(302, '/photos');
+		throw redirect(302, AppRoute.PHOTOS);
 	}
 
 	const { data: allUsers } = await api.userApi.getAllUsers({ isAll: false });

+ 2 - 1
web/src/routes/auth/register/+page.server.ts

@@ -1,11 +1,12 @@
 import { redirect } from '@sveltejs/kit';
 import type { PageServerLoad } from './$types';
+import { AppRoute } from '$lib/constants';
 
 export const load = (async ({ locals: { api } }) => {
 	const { data } = await api.userApi.getUserCount({ admin: true });
 	if (data.userCount != 0) {
 		// Admin has been registered, redirect to login
-		throw redirect(302, '/auth/login');
+		throw redirect(302, AppRoute.AUTH_LOGIN);
 	}
 
 	return {