diff --git a/app/controllers/users_controller.ts b/app/controllers/users_controller.ts index 4346c2a..244df59 100644 --- a/app/controllers/users_controller.ts +++ b/app/controllers/users_controller.ts @@ -52,7 +52,7 @@ export default class UsersController { avatarUrl, token, providerType: 'google', - isAdmin: userCount[0].total === '0', + isAdmin: userCount[0].total === '0' ? true : undefined, } ); diff --git a/inertia/app/ssr.tsx b/inertia/app/ssr.tsx index a2d010f..60a3832 100644 --- a/inertia/app/ssr.tsx +++ b/inertia/app/ssr.tsx @@ -1,5 +1,5 @@ -import ReactDOMServer from 'react-dom/server'; import { createInertiaApp } from '@inertiajs/react'; +import ReactDOMServer from 'react-dom/server'; export default function render(page: any) { return createInertiaApp({ diff --git a/inertia/components/dashboard/dashboard_provider.tsx b/inertia/components/dashboard/dashboard_provider.tsx new file mode 100644 index 0000000..90651e3 --- /dev/null +++ b/inertia/components/dashboard/dashboard_provider.tsx @@ -0,0 +1,90 @@ +import { router } from '@inertiajs/react'; +import { route } from '@izzyjs/route/client'; +import { ReactNode, useMemo, useState } from 'react'; +import { ActiveCollectionContext } from '~/contexts/active_collection_context'; +import CollectionsContext from '~/contexts/collections_context'; +import FavoritesContext from '~/contexts/favorites_context'; +import GlobalHotkeysContext from '~/contexts/global_hotkeys_context'; +import useShortcut from '~/hooks/use_shortcut'; +import { appendCollectionId } from '~/lib/navigation'; +import { CollectionWithLinks, Link } from '~/types/app'; + +export default function DashboardProviders( + props: Readonly<{ + children: ReactNode; + collections: CollectionWithLinks[]; + activeCollection: CollectionWithLinks; + }> +) { + const [globalHotkeysEnabled, setGlobalHotkeysEnabled] = + useState(true); + const [collections, setCollections] = useState( + props.collections + ); + const [activeCollection, setActiveCollection] = + useState( + props.activeCollection || collections?.[0] + ); + + const handleChangeCollection = (collection: CollectionWithLinks) => { + setActiveCollection(collection); + router.visit(appendCollectionId(route('dashboard').url, collection.id)); + }; + + const favorites = useMemo( + () => + collections.reduce((acc, collection) => { + collection.links.forEach((link) => + link.favorite ? acc.push(link) : null + ); + return acc; + }, [] as Link[]), + [collections] + ); + + const collectionsContextValue = useMemo( + () => ({ collections, setCollections }), + [collections] + ); + const activeCollectionContextValue = useMemo( + () => ({ activeCollection, setActiveCollection: handleChangeCollection }), + [activeCollection, handleChangeCollection] + ); + const favoritesContextValue = useMemo(() => ({ favorites }), [favorites]); + const globalHotkeysContextValue = useMemo( + () => ({ + globalHotkeysEnabled, + setGlobalHotkeysEnabled, + }), + [globalHotkeysEnabled] + ); + + useShortcut( + 'OPEN_CREATE_LINK_KEY', + () => + router.visit( + appendCollectionId(route('link.create-form').url, activeCollection?.id) + ), + { + enabled: globalHotkeysEnabled, + } + ); + useShortcut( + 'OPEN_CREATE_COLLECTION_KEY', + () => router.visit(route('collection.create-form').url), + { + enabled: globalHotkeysEnabled, + } + ); + return ( + + + + + {props.children} + + + + + ); +} diff --git a/inertia/components/layouts/_base_layout.tsx b/inertia/components/layouts/_base_layout.tsx index b23c740..63f5314 100644 --- a/inertia/components/layouts/_base_layout.tsx +++ b/inertia/components/layouts/_base_layout.tsx @@ -7,8 +7,9 @@ import DarkThemeContextProvider from '~/contexts/dark_theme_context'; export default function BaseLayout({ children }: { children: ReactNode }) { const { i18n } = useTranslation(); dayjs.locale(i18n.language); + console.log('a'); return ( - + {children} ); diff --git a/inertia/pages/dashboard.tsx b/inertia/pages/dashboard.tsx index 353e4d4..e4ed5fd 100644 --- a/inertia/pages/dashboard.tsx +++ b/inertia/pages/dashboard.tsx @@ -1,22 +1,15 @@ import styled from '@emotion/styled'; -import { router } from '@inertiajs/react'; -import { route } from '@izzyjs/route/client'; -import { ReactNode, useEffect, useMemo, useState } from 'react'; +import { ReactNode, useEffect } from 'react'; import { useSwipeable } from 'react-swipeable'; import CollectionContainer from '~/components/dashboard/collection/collection_container'; import CollectionList from '~/components/dashboard/collection/list/collection_list'; +import DashboardProviders from '~/components/dashboard/dashboard_provider'; import SideNavigation from '~/components/dashboard/side_nav/side_navigation'; import SwiperHandler from '~/components/dashboard/swiper_handler'; import DashboardLayout from '~/components/layouts/dashboard_layout'; -import { ActiveCollectionContext } from '~/contexts/active_collection_context'; -import CollectionsContext from '~/contexts/collections_context'; -import FavoritesContext from '~/contexts/favorites_context'; -import GlobalHotkeysContext from '~/contexts/global_hotkeys_context'; import { useMediaQuery } from '~/hooks/use_media_query'; import useToggle from '~/hooks/use_modal'; -import useShortcut from '~/hooks/use_shortcut'; -import { appendCollectionId } from '~/lib/navigation'; -import { CollectionWithLinks, Link } from '~/types/app'; +import { CollectionWithLinks } from '~/types/app'; interface DashboardPageProps { collections: CollectionWithLinks[]; @@ -28,7 +21,7 @@ const SideBar = styled.div(({ theme }) => ({ marginRight: '5px', })); -export default function DashboardPage(props: Readonly) { +function DashboardPage(props: Readonly) { const isMobile = useMediaQuery('(max-width: 768px)'); const { isShowing, open, close } = useToggle(); const handlers = useSwipeable({ @@ -43,100 +36,22 @@ export default function DashboardPage(props: Readonly) { }, [close, isMobile, isShowing]); return ( - - - - {!isMobile && ( - - - - )} - - - - - + + + {!isMobile && ( + + + + )} + + + + ); } -function DashboardProviders( - props: Readonly<{ - children: ReactNode; - collections: CollectionWithLinks[]; - activeCollection: CollectionWithLinks; - }> -) { - const [globalHotkeysEnabled, setGlobalHotkeysEnabled] = - useState(true); - const [collections, setCollections] = useState( - props.collections - ); - const [activeCollection, setActiveCollection] = - useState( - props.activeCollection || collections?.[0] - ); - const handleChangeCollection = (collection: CollectionWithLinks) => { - setActiveCollection(collection); - router.visit(appendCollectionId(route('dashboard').url, collection.id)); - }; - - const favorites = useMemo( - () => - collections.reduce((acc, collection) => { - collection.links.forEach((link) => - link.favorite ? acc.push(link) : null - ); - return acc; - }, [] as Link[]), - [collections] - ); - - const collectionsContextValue = useMemo( - () => ({ collections, setCollections }), - [collections] - ); - const activeCollectionContextValue = useMemo( - () => ({ activeCollection, setActiveCollection: handleChangeCollection }), - [activeCollection, handleChangeCollection] - ); - const favoritesContextValue = useMemo(() => ({ favorites }), [favorites]); - const globalHotkeysContextValue = useMemo( - () => ({ - globalHotkeysEnabled, - setGlobalHotkeysEnabled, - }), - [globalHotkeysEnabled] - ); - - useShortcut( - 'OPEN_CREATE_LINK_KEY', - () => - router.visit( - appendCollectionId(route('link.create-form').url, activeCollection?.id) - ), - { - enabled: globalHotkeysEnabled, - } - ); - useShortcut( - 'OPEN_CREATE_COLLECTION_KEY', - () => router.visit(route('collection.create-form').url), - { - enabled: globalHotkeysEnabled, - } - ); - return ( - - - - - {props.children} - - - - - ); -} +DashboardPage.layout = (page: ReactNode) => ; +export default DashboardPage; diff --git a/inertia/pages/home.tsx b/inertia/pages/home.tsx index 94a7266..31b26c4 100644 --- a/inertia/pages/home.tsx +++ b/inertia/pages/home.tsx @@ -1,4 +1,5 @@ import styled from '@emotion/styled'; +import { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import { AiFillFolderOpen } from 'react-icons/ai'; import { FaUser } from 'react-icons/fa'; @@ -19,10 +20,10 @@ const PageContent = styled.div({ flexDirection: 'column', }); -export default function HomePage() { +function HomePage() { const { t } = useTranslation(); return ( - + <> @@ -59,6 +60,9 @@ export default function HomePage() { - + ); } + +HomePage.layout = (page: ReactNode) => ; +export default HomePage; diff --git a/inertia/pages/login.tsx b/inertia/pages/login.tsx index 8a0fbe1..4df5a6f 100644 --- a/inertia/pages/login.tsx +++ b/inertia/pages/login.tsx @@ -1,6 +1,7 @@ import styled from '@emotion/styled'; import { Head, Link } from '@inertiajs/react'; import { route } from '@izzyjs/route/client'; +import { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import { FcGoogle } from 'react-icons/fc'; import Button from '~/components/common/form/_button'; @@ -51,32 +52,38 @@ const ButtonLink = styled(Button.withComponent('a'))({ justifyContent: 'center', }); -export default function LoginPage() { +function LoginPage() { const { t } = useTranslation(); return ( - - - - MyLinks's logo - {t('common:slogan')} - -

{t('login:title')}

- {t('login:informative-text')} - - {' '} - {t('login:continue-with', { provider: 'Google' })} - -
- - {t('login:accept-terms')}{' '} - {t('common:terms')} - -
-
+ + + MyLinks's logo + {t('common:slogan')} + +

{t('login:title')}

+ {t('login:informative-text')} + + {' '} + {t('login:continue-with', { provider: 'Google' })} + +
+ + {t('login:accept-terms')}{' '} + {t('common:terms')} + +
); } + +LoginPage.layout = (page: ReactNode) => ( + +); +export default LoginPage; diff --git a/inertia/pages/privacy.tsx b/inertia/pages/privacy.tsx index 2f59614..cb03844 100644 --- a/inertia/pages/privacy.tsx +++ b/inertia/pages/privacy.tsx @@ -1,10 +1,11 @@ +import { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import LegalContentLayout from '~/components/layouts/legal_content_layout'; -export default function TermsPage() { +function PrivacyPage() { const { t } = useTranslation('privacy'); return ( - + <>

{t('title')}

{t('edited_at', { date: '19/11/2023' })}

{t('welcome')}

@@ -39,6 +40,11 @@ export default function TermsPage() {

{t('gdpr.title')}

{t('gdpr.description')}

-
+ ); } + +PrivacyPage.layout = (page: ReactNode) => ( + +); +export default PrivacyPage; diff --git a/inertia/pages/terms.tsx b/inertia/pages/terms.tsx index 7132166..32d6620 100644 --- a/inertia/pages/terms.tsx +++ b/inertia/pages/terms.tsx @@ -1,12 +1,13 @@ import { Link } from '@inertiajs/react'; import { route } from '@izzyjs/route/client'; +import { ReactNode } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import LegalContentLayout from '~/components/layouts/legal_content_layout'; -export default function TermsPage() { +function TermsPage() { const { t } = useTranslation('terms'); return ( - + <>

{t('title')}

{t('edited_at', { date: '19/11/2023' })}

{t('welcome')}

@@ -48,6 +49,9 @@ export default function TermsPage() {

{t('cancel.title')}

{t('cancel.description')}

-
+ ); } + +TermsPage.layout = (page: ReactNode) => ; +export default TermsPage;