From db2204258a9017f10874678790eeb9cbb8488ec1 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 00:49:32 +0200 Subject: [PATCH 1/9] Add setup step in /info --- .../Models/DTO/ServerInfo.cs | 26 +++++++++++++++++++ .../Kyoo.Core/Controllers/MiscRepository.cs | 10 +++++++ .../Views/InfoApi.cs | 7 +++-- 3 files changed, 41 insertions(+), 2 deletions(-) rename back/src/{Kyoo.Authentication => Kyoo.Core}/Views/InfoApi.cs (87%) diff --git a/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs index 9a581ed9..6286cb7c 100644 --- a/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs +++ b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs @@ -46,6 +46,11 @@ public class ServerInfo /// The list of permissions available for the guest account. /// public List GuestPermissions { get; set; } + + /// + /// Check if kyoo's setup is finished. + /// + public SetupStep SetupStatus { get; set; } } public class OidcInfo @@ -60,3 +65,24 @@ public class OidcInfo /// public string? LogoUrl { get; set; } } + +/// +/// Check if kyoo's setup is finished. +/// +public enum SetupStep +{ + /// + /// No admin account exists, create an account before exposing kyoo to the internet! + /// + MissingAdminAccount, + + /// + /// No video was registered on kyoo, have you configured the rigth library path? + /// + NoVideoFound, + + /// + /// Setup finished! + /// + Done, +} diff --git a/back/src/Kyoo.Core/Controllers/MiscRepository.cs b/back/src/Kyoo.Core/Controllers/MiscRepository.cs index 8b014840..48916ad8 100644 --- a/back/src/Kyoo.Core/Controllers/MiscRepository.cs +++ b/back/src/Kyoo.Core/Controllers/MiscRepository.cs @@ -25,6 +25,7 @@ using System.Threading.Tasks; using Dapper; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; +using Kyoo.Authentication.Models; using Kyoo.Postgresql; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -129,6 +130,15 @@ public class MiscRepository( .OrderBy(x => x.RefreshDate) .ToListAsync(); } + + public async Task GetSetupStep() + { + bool hasUser = await context.Users.AnyAsync(); + if (!hasUser) + return SetupStep.MissingAdminAccount; + bool hasItem = await context.Movies.AnyAsync() || await context.Shows.AnyAsync(); + return hasItem ? SetupStep.Done : SetupStep.NoVideoFound; + } } public class RefreshableItem diff --git a/back/src/Kyoo.Authentication/Views/InfoApi.cs b/back/src/Kyoo.Core/Views/InfoApi.cs similarity index 87% rename from back/src/Kyoo.Authentication/Views/InfoApi.cs rename to back/src/Kyoo.Core/Views/InfoApi.cs index ceb8ab4e..113e32f2 100644 --- a/back/src/Kyoo.Authentication/Views/InfoApi.cs +++ b/back/src/Kyoo.Core/Views/InfoApi.cs @@ -18,8 +18,10 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Authentication.Models; +using Kyoo.Core.Controllers; using Microsoft.AspNetCore.Mvc; using static Kyoo.Abstractions.Models.Utils.Constants; @@ -31,9 +33,9 @@ namespace Kyoo.Authentication.Views; [ApiController] [Route("info")] [ApiDefinition("Info", Group = UsersGroup)] -public class InfoApi(PermissionOption options) : ControllerBase +public class InfoApi(PermissionOption options, MiscRepository info) : ControllerBase { - public ActionResult GetInfo() + public async Task> GetInfo() { return Ok( new ServerInfo() @@ -48,6 +50,7 @@ public class InfoApi(PermissionOption options) : ControllerBase new() { DisplayName = x.Value.DisplayName, LogoUrl = x.Value.LogoUrl, } )) .ToDictionary(x => x.Key, x => x.Value), + SetupStatus = await info.GetSetupStep() } ); } From 97e3257aee2ddf4d8657aebe526774a145d2bbee Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 02:05:23 +0200 Subject: [PATCH 2/9] Add setup page componant --- back/src/Kyoo.Core/Views/InfoApi.cs | 2 +- front/apps/web/src/pages/setup/index.tsx | 24 +++++++++++++ .../models/src/resources/server-info.ts | 10 ++++++ front/packages/ui/src/errors/index.tsx | 1 + front/packages/ui/src/errors/setup.tsx | 31 +++++++++++++++++ front/packages/ui/src/navbar/index.tsx | 34 ++++++++++++------- front/translations/en.json | 6 +++- 7 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 front/apps/web/src/pages/setup/index.tsx create mode 100644 front/packages/ui/src/errors/setup.tsx diff --git a/back/src/Kyoo.Core/Views/InfoApi.cs b/back/src/Kyoo.Core/Views/InfoApi.cs index 113e32f2..48cd132d 100644 --- a/back/src/Kyoo.Core/Views/InfoApi.cs +++ b/back/src/Kyoo.Core/Views/InfoApi.cs @@ -50,7 +50,7 @@ public class InfoApi(PermissionOption options, MiscRepository info) : Controller new() { DisplayName = x.Value.DisplayName, LogoUrl = x.Value.LogoUrl, } )) .ToDictionary(x => x.Key, x => x.Value), - SetupStatus = await info.GetSetupStep() + SetupStatus = await info.GetSetupStep(), } ); } diff --git a/front/apps/web/src/pages/setup/index.tsx b/front/apps/web/src/pages/setup/index.tsx new file mode 100644 index 00000000..022e242e --- /dev/null +++ b/front/apps/web/src/pages/setup/index.tsx @@ -0,0 +1,24 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +import { SetupPage } from "@kyoo/ui"; +import { withRoute } from "~/router"; + +export default withRoute(SetupPage); diff --git a/front/packages/models/src/resources/server-info.ts b/front/packages/models/src/resources/server-info.ts index 370ba6d2..05fa90e6 100644 --- a/front/packages/models/src/resources/server-info.ts +++ b/front/packages/models/src/resources/server-info.ts @@ -33,6 +33,12 @@ export const OidcInfoP = z.object({ logoUrl: z.string().nullable(), }); +export enum SetupStep { + MissingAdminAccount = "MissingAdminAccount", + NoVideoFound = "NoVideoFound", + Done = "Done", +} + export const ServerInfoP = z .object({ /* @@ -51,6 +57,10 @@ export const ServerInfoP = z * The list of oidc providers configured for this instance of kyoo. */ oidc: z.record(z.string(), OidcInfoP), + /* + * Check if kyoo's setup is finished. + */ + setupStatus: z.nativeEnum(SetupStep), }) .transform((x) => { const baseUrl = Platform.OS === "web" ? x.publicUrl : "kyoo://"; diff --git a/front/packages/ui/src/errors/index.tsx b/front/packages/ui/src/errors/index.tsx index c7a6e21b..19c9c722 100644 --- a/front/packages/ui/src/errors/index.tsx +++ b/front/packages/ui/src/errors/index.tsx @@ -21,3 +21,4 @@ export * from "./error"; export * from "./unauthorized"; export * from "./connection"; +export * from "./setup"; diff --git a/front/packages/ui/src/errors/setup.tsx b/front/packages/ui/src/errors/setup.tsx new file mode 100644 index 00000000..eeb239db --- /dev/null +++ b/front/packages/ui/src/errors/setup.tsx @@ -0,0 +1,31 @@ +import { SetupStep, type QueryPage } from "@kyoo/models"; +import { Button, Icon, Link, P, ts } from "@kyoo/primitives"; +import { useTranslation } from "react-i18next"; +import { Main } from "@expo/html-elements"; +import { useYoshiki } from "yoshiki/native"; +import Register from "@material-symbols/svg-400/rounded/app_registration.svg"; +import { Navbar, NavbarProfile } from "../navbar"; + +export const SetupPage: QueryPage<{ step: Exclude }> = ({ step }) => { + const { css } = useYoshiki(); + const { t } = useTranslation(); + + return ( + <> + } /> +
+

{t(`errors.setup.${step}`)}

+ {step === SetupStep.MissingAdminAccount && ( +
+ + ); +}; diff --git a/front/packages/ui/src/navbar/index.tsx b/front/packages/ui/src/navbar/index.tsx index ec001dc4..31ed2a33 100644 --- a/front/packages/ui/src/navbar/index.tsx +++ b/front/packages/ui/src/navbar/index.tsx @@ -38,7 +38,7 @@ import Login from "@material-symbols/svg-400/rounded/login.svg"; import Logout from "@material-symbols/svg-400/rounded/logout.svg"; import Search from "@material-symbols/svg-400/rounded/search-fill.svg"; import Settings from "@material-symbols/svg-400/rounded/settings.svg"; -import { forwardRef, useEffect, useRef, useState } from "react"; +import { ReactElement, forwardRef, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Platform, type TextInput, View, type ViewProps } from "react-native"; import { useRouter } from "solito/router"; @@ -168,7 +168,11 @@ export const NavbarRight = () => { ); }; -export const Navbar = (props: Stylable) => { +export const Navbar = ({ + left, + right, + ...props +}: { left?: ReactElement | null; right?: ReactElement | null }) => { const { css } = useYoshiki(); const { t } = useTranslation(); @@ -197,16 +201,20 @@ export const Navbar = (props: Stylable) => { > - theme.contrast, - })} - > - {t("navbar.browse")} - + {left !== undefined ? ( + left + ) : ( + theme.contrast, + })} + > + {t("navbar.browse")} + + )} { marginX: ts(2), })} /> - + {right !== undefined ? right : } ); }; diff --git a/front/translations/en.json b/front/translations/en.json index d004aed0..89a285bc 100644 --- a/front/translations/en.json +++ b/front/translations/en.json @@ -237,7 +237,11 @@ "offline": "You are not connected to internet. Try again later.", "unauthorized": "You are missing the permissions {{permission}} to access this page.", "needVerification": "Your account needs to be verified by your server administrator before you can use it.", - "needAccount": "This page can't be accessed in guest mode. You need to create an account or login." + "needAccount": "This page can't be accessed in guest mode. You need to create an account or login.", + "setup": { + "MissingAdminAccount": "No admin account has been created yet. Please register to create one.", + "NoVideoFound": "No video was found yet. Add movies or series inside your library's folder for them to show here!" + } }, "mediainfo": { "file": "File", From cdf482ac4a536cfa595305ee95860a90da7e4877 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 15:49:10 +0200 Subject: [PATCH 3/9] Cleanup setup page layout --- front/packages/ui/src/errors/setup.tsx | 46 ++++++++++++++++---------- front/packages/ui/src/navbar/index.tsx | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/front/packages/ui/src/errors/setup.tsx b/front/packages/ui/src/errors/setup.tsx index eeb239db..a827eca1 100644 --- a/front/packages/ui/src/errors/setup.tsx +++ b/front/packages/ui/src/errors/setup.tsx @@ -5,27 +5,39 @@ import { Main } from "@expo/html-elements"; import { useYoshiki } from "yoshiki/native"; import Register from "@material-symbols/svg-400/rounded/app_registration.svg"; import { Navbar, NavbarProfile } from "../navbar"; +import { useEffect } from "react"; +import { useRouter } from "solito/router"; -export const SetupPage: QueryPage<{ step: Exclude }> = ({ step }) => { +export const SetupPage: QueryPage<{ step: SetupStep }> = ({ step }) => { const { css } = useYoshiki(); const { t } = useTranslation(); + const router = useRouter(); + const isValid = Object.values(SetupStep).includes(step) && step !== SetupStep.Done; + + useEffect(() => { + if (!isValid) router.replace("/"); + }, [isValid, router]); + + if (!isValid) return

Loading...

; return ( - <> - } /> -
-

{t(`errors.setup.${step}`)}

- {step === SetupStep.MissingAdminAccount && ( -
- +
+

{t(`errors.setup.${step}`)}

+ {step === SetupStep.MissingAdminAccount && ( +
); }; + +SetupPage.getLayout = ({ page }) => ( + <> + } /> + {page} + +); diff --git a/front/packages/ui/src/navbar/index.tsx b/front/packages/ui/src/navbar/index.tsx index 31ed2a33..a82109fc 100644 --- a/front/packages/ui/src/navbar/index.tsx +++ b/front/packages/ui/src/navbar/index.tsx @@ -172,7 +172,7 @@ export const Navbar = ({ left, right, ...props -}: { left?: ReactElement | null; right?: ReactElement | null }) => { +}: { left?: ReactElement | null; right?: ReactElement | null } & Stylable) => { const { css } = useYoshiki(); const { t } = useTranslation(); From d178b78e8666090ae76bac3a195426f528874a05 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 15:49:28 +0200 Subject: [PATCH 4/9] Check setup step and redirect to /setup if needed --- front/apps/web/src/pages/_app.tsx | 40 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 7b3c156c..35dda215 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -34,6 +34,8 @@ import { getTokenWJ, setSsrApiUrl, useUserTheme, + SetupStep, + ServerInfo, } from "@kyoo/models"; import { getCurrentAccount, readCookie, updateAccount } from "@kyoo/models/src/account-internal"; import { @@ -56,6 +58,8 @@ import { Tooltip } from "react-tooltip"; import superjson from "superjson"; import { StyleRegistryProvider, useMobileHover, useStyleRegistry, useTheme } from "yoshiki/web"; import { withTranslations } from "../i18n"; +import { redirect } from "next/navigation"; +import { NextResponse } from "next/server"; const font = Poppins({ weight: ["300", "400", "900"], subsets: ["latin"], display: "swap" }); @@ -214,22 +218,36 @@ App.getInitialProps = async (ctx: AppContext) => { setSsrApiUrl(); + appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto"; + const account = readCookie(ctx.ctx.req?.headers.cookie, "account", AccountP); if (account) urls.push({ path: ["auth", "me"], parser: UserP }); const [authToken, token, error] = await getTokenWJ(account); if (error) appProps.pageProps.ssrError = error; - else { - const client = (await fetchQuery(urls, authToken))!; - appProps.pageProps.queryState = dehydrate(client); - if (account) { - appProps.pageProps.token = token; - appProps.pageProps.account = { - ...client.getQueryData(["auth", "me"]), - ...account, - }; - } + const client = (await fetchQuery(urls, authToken))!; + appProps.pageProps.queryState = dehydrate(client); + if (account) { + appProps.pageProps.token = token; + appProps.pageProps.account = { + ...client.getQueryData(["auth", "me"]), + ...account, + }; + } + + const info = client.getQueryData(["info"]); + if ( + info!.setupStatus !== SetupStep.Done && + !( + (ctx.router.route === "/setup" && ctx.router.query.step === info!.setupStatus) || + ctx.router.route === "/register" || + ctx.router.route === "/login" || + ctx.router.route === "/settings" + ) + ) { + ctx.ctx.res!.writeHead(307, { Location: `/setup?step=${info!.setupStatus}` }); + ctx.ctx.res!.end(); + return {} as any; } - appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto"; } catch (e) { console.error("SSR error, disabling it."); } From cc3f6f611e57b23a26a5ef5930a844901a967ba6 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 17:44:42 +0200 Subject: [PATCH 5/9] Center logo in navbar --- front/packages/ui/src/errors/setup.tsx | 17 +++++++----- front/packages/ui/src/navbar/index.tsx | 36 ++++++++++++++++---------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/front/packages/ui/src/errors/setup.tsx b/front/packages/ui/src/errors/setup.tsx index a827eca1..4d434417 100644 --- a/front/packages/ui/src/errors/setup.tsx +++ b/front/packages/ui/src/errors/setup.tsx @@ -7,6 +7,7 @@ import Register from "@material-symbols/svg-400/rounded/app_registration.svg"; import { Navbar, NavbarProfile } from "../navbar"; import { useEffect } from "react"; import { useRouter } from "solito/router"; +import { KyooLongLogo } from "../navbar/icon"; export const SetupPage: QueryPage<{ step: SetupStep }> = ({ step }) => { const { css } = useYoshiki(); @@ -35,9 +36,13 @@ export const SetupPage: QueryPage<{ step: SetupStep }> = ({ step }) => { ); }; -SetupPage.getLayout = ({ page }) => ( - <> - } /> - {page} - -); +SetupPage.getLayout = ({ page }) => { + const { css } = useYoshiki(); + + return ( + <> + } right={} /> + {page} + + ); +}; diff --git a/front/packages/ui/src/navbar/index.tsx b/front/packages/ui/src/navbar/index.tsx index a82109fc..9aeaaafc 100644 --- a/front/packages/ui/src/navbar/index.tsx +++ b/front/packages/ui/src/navbar/index.tsx @@ -42,15 +42,21 @@ import { ReactElement, forwardRef, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Platform, type TextInput, View, type ViewProps } from "react-native"; import { useRouter } from "solito/router"; -import { type Stylable, useYoshiki } from "yoshiki/native"; +import { type Stylable, useYoshiki, percent } from "yoshiki/native"; import { AdminPage } from "../admin"; import { KyooLongLogo } from "./icon"; export const NavbarTitle = (props: Stylable & { onLayout?: ViewProps["onLayout"] }) => { const { t } = useTranslation(); + const { css } = useYoshiki(); return ( - + ); @@ -199,21 +205,23 @@ export const Navbar = ({ props, )} > - - + {left !== undefined ? ( left ) : ( - theme.contrast, - })} - > - {t("navbar.browse")} - + <> + + theme.contrast, + })} + > + {t("navbar.browse")} + + )} Date: Sun, 26 May 2024 18:28:32 +0200 Subject: [PATCH 6/9] Redirect to /setup when navigating away --- front/apps/web/src/pages/_app.tsx | 37 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 35dda215..11662192 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -35,7 +35,8 @@ import { setSsrApiUrl, useUserTheme, SetupStep, - ServerInfo, + type ServerInfo, + useFetch, } from "@kyoo/models"; import { getCurrentAccount, readCookie, updateAccount } from "@kyoo/models/src/account-internal"; import { @@ -53,13 +54,12 @@ import arrayShuffle from "array-shuffle"; import NextApp, { type AppContext, type AppProps } from "next/app"; import { Poppins } from "next/font/google"; import Head from "next/head"; -import { type ComponentType, useContext, useState } from "react"; +import { type ComponentType, useContext, useState, useEffect } from "react"; import { Tooltip } from "react-tooltip"; import superjson from "superjson"; import { StyleRegistryProvider, useMobileHover, useStyleRegistry, useTheme } from "yoshiki/web"; import { withTranslations } from "../i18n"; -import { redirect } from "next/navigation"; -import { NextResponse } from "next/server"; +import { NextRouter, useRouter } from "next/router"; const font = Poppins({ weight: ["300", "400", "900"], subsets: ["latin"], display: "swap" }); @@ -135,6 +135,27 @@ const ConnectionErrorVerifier = ({ return ; }; +const SetupChecker = () => { + const { data } = useFetch({ path: ["info"], parser: ServerInfoP }); + const router = useRouter(); + + const step = data?.setupStatus; + + useEffect(() => { + if (!step) return; + if (step !== SetupStep.Done && !SetupChecker.isRouteAllowed(router, step)) + router.push(`/setup?step=${step}`); + }, [router.route, step, router]); + + return null; +}; + +SetupChecker.isRouteAllowed = (router: NextRouter, step: SetupStep) => + (router.route === "/setup" && router.query.step === step) || + router.route === "/register" || + router.route.startsWith("/login") || + router.route === "/settings"; + const WithLayout = ({ Component, ...props }: { Component: ComponentType }) => { const layoutInfo = (Component as QueryPage).getLayout ?? (({ page }) => page); const { Layout, props: layoutProps } = @@ -180,6 +201,7 @@ const App = ({ Component, pageProps }: AppProps) => { /> + @@ -237,12 +259,7 @@ App.getInitialProps = async (ctx: AppContext) => { const info = client.getQueryData(["info"]); if ( info!.setupStatus !== SetupStep.Done && - !( - (ctx.router.route === "/setup" && ctx.router.query.step === info!.setupStatus) || - ctx.router.route === "/register" || - ctx.router.route === "/login" || - ctx.router.route === "/settings" - ) + !SetupChecker.isRouteAllowed(ctx.router, info!.setupStatus) ) { ctx.ctx.res!.writeHead(307, { Location: `/setup?step=${info!.setupStatus}` }); ctx.ctx.res!.end(); From a9a74ddc14c863e2eb08d022340edf837a3a42be Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 18:32:06 +0200 Subject: [PATCH 7/9] Redirect to home page when setup is finished --- front/apps/web/src/pages/_app.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 11662192..9bf3e833 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -145,6 +145,7 @@ const SetupChecker = () => { if (!step) return; if (step !== SetupStep.Done && !SetupChecker.isRouteAllowed(router, step)) router.push(`/setup?step=${step}`); + if (step === SetupStep.Done && router.route === "/setup") router.replace("/"); }, [router.route, step, router]); return null; From e015882834e36277d4311832235de110a2752262 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 18:36:34 +0200 Subject: [PATCH 8/9] Redirect to / when setup is done in ssr mode --- front/apps/web/src/pages/_app.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 9bf3e833..4f2d07b1 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -266,6 +266,11 @@ App.getInitialProps = async (ctx: AppContext) => { ctx.ctx.res!.end(); return {} as any; } + if (info!.setupStatus === SetupStep.Done && ctx.router.route === "/setup") { + ctx.ctx.res!.writeHead(307, { Location: "/" }); + ctx.ctx.res!.end(); + return {} as any; + } } catch (e) { console.error("SSR error, disabling it."); } From 21e1fa6376b692950a9ada593eb27f78e5135056 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 May 2024 18:39:38 +0200 Subject: [PATCH 9/9] Format code --- front/apps/web/src/pages/_app.tsx | 10 +++++----- front/packages/ui/src/errors/setup.tsx | 10 +++++----- front/packages/ui/src/navbar/index.tsx | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 4f2d07b1..28db2a8c 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -27,16 +27,16 @@ import { ConnectionErrorContext, type QueryIdentifier, type QueryPage, + type ServerInfo, ServerInfoP, + SetupStep, UserP, createQueryClient, fetchQuery, getTokenWJ, setSsrApiUrl, - useUserTheme, - SetupStep, - type ServerInfo, useFetch, + useUserTheme, } from "@kyoo/models"; import { getCurrentAccount, readCookie, updateAccount } from "@kyoo/models/src/account-internal"; import { @@ -54,12 +54,12 @@ import arrayShuffle from "array-shuffle"; import NextApp, { type AppContext, type AppProps } from "next/app"; import { Poppins } from "next/font/google"; import Head from "next/head"; -import { type ComponentType, useContext, useState, useEffect } from "react"; +import { type NextRouter, useRouter } from "next/router"; +import { type ComponentType, useContext, useEffect, useState } from "react"; import { Tooltip } from "react-tooltip"; import superjson from "superjson"; import { StyleRegistryProvider, useMobileHover, useStyleRegistry, useTheme } from "yoshiki/web"; import { withTranslations } from "../i18n"; -import { NextRouter, useRouter } from "next/router"; const font = Poppins({ weight: ["300", "400", "900"], subsets: ["latin"], display: "swap" }); diff --git a/front/packages/ui/src/errors/setup.tsx b/front/packages/ui/src/errors/setup.tsx index 4d434417..ef41dd28 100644 --- a/front/packages/ui/src/errors/setup.tsx +++ b/front/packages/ui/src/errors/setup.tsx @@ -1,12 +1,12 @@ -import { SetupStep, type QueryPage } from "@kyoo/models"; -import { Button, Icon, Link, P, ts } from "@kyoo/primitives"; -import { useTranslation } from "react-i18next"; import { Main } from "@expo/html-elements"; -import { useYoshiki } from "yoshiki/native"; +import { type QueryPage, SetupStep } from "@kyoo/models"; +import { Button, Icon, Link, P, ts } from "@kyoo/primitives"; import Register from "@material-symbols/svg-400/rounded/app_registration.svg"; -import { Navbar, NavbarProfile } from "../navbar"; import { useEffect } from "react"; +import { useTranslation } from "react-i18next"; import { useRouter } from "solito/router"; +import { useYoshiki } from "yoshiki/native"; +import { Navbar, NavbarProfile } from "../navbar"; import { KyooLongLogo } from "../navbar/icon"; export const SetupPage: QueryPage<{ step: SetupStep }> = ({ step }) => { diff --git a/front/packages/ui/src/navbar/index.tsx b/front/packages/ui/src/navbar/index.tsx index 9aeaaafc..d2ccf7b6 100644 --- a/front/packages/ui/src/navbar/index.tsx +++ b/front/packages/ui/src/navbar/index.tsx @@ -38,11 +38,11 @@ import Login from "@material-symbols/svg-400/rounded/login.svg"; import Logout from "@material-symbols/svg-400/rounded/logout.svg"; import Search from "@material-symbols/svg-400/rounded/search-fill.svg"; import Settings from "@material-symbols/svg-400/rounded/settings.svg"; -import { ReactElement, forwardRef, useEffect, useRef, useState } from "react"; +import { type ReactElement, forwardRef, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Platform, type TextInput, View, type ViewProps } from "react-native"; import { useRouter } from "solito/router"; -import { type Stylable, useYoshiki, percent } from "yoshiki/native"; +import { type Stylable, percent, useYoshiki } from "yoshiki/native"; import { AdminPage } from "../admin"; import { KyooLongLogo } from "./icon";