diff --git a/next-tavla/app/(admin)/components/CreateBoard/components/StopPlaceList.tsx b/next-tavla/app/(admin)/components/CreateBoard/components/StopPlaceList.tsx index 4e93a01db..3a72b76d0 100644 --- a/next-tavla/app/(admin)/components/CreateBoard/components/StopPlaceList.tsx +++ b/next-tavla/app/(admin)/components/CreateBoard/components/StopPlaceList.tsx @@ -11,8 +11,8 @@ function StopPlaceList({ }) { if (!tiles || tiles.length === 0) return ( - - Du har ikke lagt til noen stoppesteder enda. + + Du har ikke lagt til noen stoppesteder ennå. ) return ( diff --git a/next-tavla/app/(admin)/components/Footer/index.tsx b/next-tavla/app/(admin)/components/Footer/index.tsx index 6dc6cfd6f..a6c300d23 100644 --- a/next-tavla/app/(admin)/components/Footer/index.tsx +++ b/next-tavla/app/(admin)/components/Footer/index.tsx @@ -51,6 +51,11 @@ function Footer() {
Informasjon +
+ + Prøv Tavla + +
setIsOpen(false)} size="medium" - className="h-full w-9/12 fixed top-0 left-0 py-10 !max-h-full !rounded-none !p-0 overflow-visible" + className="!h-full !w-9/12 !fixed !top-0 !left-0 py-10 !max-h-full !rounded-none !p-0 overflow-visible" > - +
- Meny + Meny
diff --git a/next-tavla/app/(admin)/components/TopNavigation.tsx b/next-tavla/app/(admin)/components/TopNavigation.tsx index ef1204174..1466f8d5b 100644 --- a/next-tavla/app/(admin)/components/TopNavigation.tsx +++ b/next-tavla/app/(admin)/components/TopNavigation.tsx @@ -5,8 +5,11 @@ import TavlaLogoBlue from 'assets/logos/Tavla-blue.svg' import { SideNavBar } from './SideNavBar' import { HorizontalNavBar } from './HorizontalNavBar' import { Login } from './Login' +import { TopNavigationItem } from '@entur/menu' +import { usePathname } from 'next/navigation' function TopNavigation({ loggedIn }: { loggedIn: boolean }) { + const pathname = usePathname() return ( ) diff --git a/next-tavla/app/(admin)/edit/[id]/components/TileCard/index.tsx b/next-tavla/app/(admin)/edit/[id]/components/TileCard/index.tsx index 2b4df22c7..82d798eed 100644 --- a/next-tavla/app/(admin)/edit/[id]/components/TileCard/index.tsx +++ b/next-tavla/app/(admin)/edit/[id]/components/TileCard/index.tsx @@ -20,9 +20,9 @@ import { TransportIcon } from 'components/TransportIcon' import { isArray, uniqBy } from 'lodash' import Image from 'next/image' import { usePostHog } from 'posthog-js/react' -import { useState } from 'react' +import { Dispatch, SetStateAction, useState } from 'react' import { Columns, TColumn } from 'types/column' -import { TBoardID } from 'types/settings' +import { TBoard, TBoardID } from 'types/settings' import { getBoard, getWalkingDistanceTile } from '../../actions' import { deleteTile, getOrganizationForBoard, saveTile } from './actions' import { useLines } from './useLines' @@ -36,10 +36,14 @@ function TileCard({ bid, tile, address, + demoBoard, + setDemoBoard, }: { bid: TBoardID tile: TTile address?: TLocation + demoBoard?: TBoard + setDemoBoard?: Dispatch> }) { const posthog = usePostHog() const [isOpen, setIsOpen] = useState(false) @@ -85,6 +89,24 @@ function TileCard({ else posthog.capture('EDIT_COLUMN_CHANGE') } + const saveTileToDemoBoard = (newTile: TTile) => { + if (!demoBoard) return null + const oldTileIndex = demoBoard.tiles.findIndex( + (tile) => tile.uuid == newTile.uuid, + ) + if (oldTileIndex === -1) return null + demoBoard.tiles[oldTileIndex] = newTile + setDemoBoard && setDemoBoard({ ...demoBoard }) + } + + const removeTileFromDemoBoard = (tile: TTile) => { + if (!demoBoard) return null + const remainingTiles = demoBoard.tiles.filter( + (t) => t.uuid !== tile.uuid, + ) + setDemoBoard && setDemoBoard({ ...demoBoard, tiles: remainingTiles }) + } + return (
{ - await deleteTile(bid, tile) + bid === 'demo' + ? removeTileFromDemoBoard(tile) + : await deleteTile(bid, tile) }} aria-label="Slett stoppested" > @@ -165,7 +189,10 @@ function TileCard({ ), ) } - saveTile(bid, newTile) + + bid === 'demo' + ? saveTileToDemoBoard(newTile) + : saveTile(bid, newTile) }} onSubmit={reset} onInput={() => setChanged(true)} @@ -178,8 +205,9 @@ function TileCard({
{!address?.name && ( )} (key: string, defaultValue: T) => { + const [localStorageValue, setLocalStorageValue] = useState(() => { + try { + const value = localStorage.getItem(key) + + if (value) { + return JSON.parse(value) + } else { + localStorage.setItem(key, JSON.stringify(defaultValue)) + return defaultValue + } + } catch (error) { + localStorage.setItem(key, JSON.stringify(defaultValue)) + return defaultValue + } + }) + + useEffect(() => { + localStorage.setItem(key, JSON.stringify(localStorageValue)) + }, [key, localStorageValue]) + + return [localStorageValue, setLocalStorageValue] +} + +export default useLocalStorage diff --git a/next-tavla/app/(admin)/layout.tsx b/next-tavla/app/(admin)/layout.tsx index 55223189d..cb185dafc 100644 --- a/next-tavla/app/(admin)/layout.tsx +++ b/next-tavla/app/(admin)/layout.tsx @@ -1,22 +1,12 @@ import { Metadata } from 'next' import { ReactNode } from 'react' -import { cookies } from 'next/headers' -import { TopNavigation } from './components/TopNavigation' -import { verifySession } from './utils/firebase' export const metadata: Metadata = { title: 'Mine organisasjoner | Entur Tavla', } async function AdminLayout({ children }: { children: ReactNode }) { - const session = cookies().get('session')?.value - const loggedIn = (await verifySession(session)) !== null - return ( - <> - -
{children}
- - ) + return
{children}
} export default AdminLayout diff --git a/next-tavla/app/demo/components/CreateUserButton.tsx b/next-tavla/app/demo/components/CreateUserButton.tsx new file mode 100644 index 000000000..fb0644bf6 --- /dev/null +++ b/next-tavla/app/demo/components/CreateUserButton.tsx @@ -0,0 +1,32 @@ +'use client' + +import { Button } from '@entur/button' +import { Heading3, Paragraph } from '@entur/typography' +import Link from 'next/link' +import { usePostHog } from 'posthog-js/react' + +export const CreateUserButton = () => { + const posthog = usePostHog() + + return ( +
+ Opprett bruker + + Det er helt gratis å bruke Tavla! + + +
+ ) +} + +export default CreateUserButton diff --git a/next-tavla/app/demo/components/DemoBoard.tsx b/next-tavla/app/demo/components/DemoBoard.tsx new file mode 100644 index 000000000..11b1978f6 --- /dev/null +++ b/next-tavla/app/demo/components/DemoBoard.tsx @@ -0,0 +1,52 @@ +'use client' +import { Heading2 } from '@entur/typography' +import { TileSelector } from 'app/(admin)/components/TileSelector' +import { formDataToTile } from 'app/(admin)/components/TileSelector/utils' +import { Preview } from 'app/(admin)/edit/[id]/components/Preview' +import { TileCard } from 'app/(admin)/edit/[id]/components/TileCard' +import useLocalStorage from '../../(admin)/hooks/useLocalStorage' +import { TTile } from 'types/tile' +import { usePostHog } from 'posthog-js/react' + +const emptyDemoBoard = { + id: 'demo', + meta: { title: 'Demo' }, + tiles: [], +} + +function DemoBoard() { + const [board, setBoard] = useLocalStorage('board', emptyDemoBoard) + + const posthog = usePostHog() + + return ( + <> +
+ Hvilke stoppesteder vil du vise i tavlen? + { + const tile = formDataToTile(data) + setBoard({ ...board, tiles: [...board.tiles, tile] }) + posthog.capture('ADD_STOP_PLACE_DEMO_PAGE') + }} + col={false} + /> + {board.tiles?.map((tile: TTile) => ( + + ))} +
+
+ Forhåndsvisning + +
+ + ) +} + +export { DemoBoard } diff --git a/next-tavla/app/demo/page.tsx b/next-tavla/app/demo/page.tsx new file mode 100644 index 000000000..da941773f --- /dev/null +++ b/next-tavla/app/demo/page.tsx @@ -0,0 +1,62 @@ +import { + Heading1, + Heading2, + LeadParagraph, + ListItem, + Paragraph, + UnorderedList, +} from '@entur/typography' +import { verifySession } from 'app/(admin)/utils/firebase' +import { cookies } from 'next/headers' +import { DemoBoard } from './components/DemoBoard' +import CreateUserButton from './components/CreateUserButton' + +async function Demo() { + const session = cookies().get('session')?.value + const loggedIn = (await verifySession(session)) !== null + + return ( +
+
+ Prøv og lag din egen avgangstavle! + + Dette er en demo-løsning hvor du kan prøve å opprette din + egen tavle. Du må logge inn for å lagre tavlen og få tilgang + til all funksjonalitet. Tavlen du lager her blir ikke + lagret. + +
+ {!loggedIn && } + +
+ Lag en demo-tavle + +
+
+ Innstillinger som krever innlogging + Hvis du logger inn, kan du: + + Endre tekststørrelse + + Legge til en info-melding nederst i tavlen + + Endre fargetema (lys eller mørk modus) + + Legge inn adressen som tavlen står på og vise gåavstand + fra tavlen til stoppested(ene) + + + Opprette så mange tavler du vil og samle disse i ulike + organisasjoner (mapper) + + + Gi andre tilgang til å administrere tavlen + + +
+ {!loggedIn && } +
+ ) +} + +export default Demo diff --git a/next-tavla/app/layout.tsx b/next-tavla/app/layout.tsx index df00c31ba..993194162 100644 --- a/next-tavla/app/layout.tsx +++ b/next-tavla/app/layout.tsx @@ -9,6 +9,9 @@ import dynamic from 'next/dynamic' import { EnturToastProvider, PHProvider } from './providers' import { Footer } from './(admin)/components/Footer' import { FloatingContact } from './components/FloatingContact' +import { TopNavigation } from './(admin)/components/TopNavigation' +import { cookies } from 'next/headers' +import { verifySession } from './(admin)/utils/firebase' export const metadata: Metadata = { title: 'Entur Tavla', @@ -38,12 +41,15 @@ const PostHogPageView = dynamic(() => import('./components/PostHogPageView'), { ssr: false, }) -function RootLayout({ children }: { children: ReactNode }) { +async function RootLayout({ children }: { children: ReactNode }) { + const session = cookies().get('session')?.value + const loggedIn = (await verifySession(session)) !== null return ( + {children} diff --git a/next-tavla/app/page.tsx b/next-tavla/app/page.tsx index a3877d17d..5f1c6f134 100644 --- a/next-tavla/app/page.tsx +++ b/next-tavla/app/page.tsx @@ -1,8 +1,5 @@ -import { verifySession } from './(admin)/utils/firebase' import landingImage from 'assets/illustrations/Main_city_2.svg' import { Metadata } from 'next' -import { cookies } from 'next/headers' -import { TopNavigation } from './(admin)/components/TopNavigation' import Image from 'next/image' import { Heading1, @@ -19,13 +16,9 @@ export const metadata: Metadata = { title: 'Forside | Entur Tavla', } -async function Landing() { - const session = cookies().get('session')?.value - const loggedIn = (await verifySession(session)) !== null - +function Landing() { return ( <> -
diff --git a/next-tavla/app/privacy/page.tsx b/next-tavla/app/privacy/page.tsx index 355c60f6f..3d28a1c99 100644 --- a/next-tavla/app/privacy/page.tsx +++ b/next-tavla/app/privacy/page.tsx @@ -4,22 +4,15 @@ import doves from 'assets/illustrations/Doves.png' import hedgehog from 'assets/illustrations/Hedgehog.png' import squirrel from 'assets/illustrations/Squirrel.png' import Image from 'next/image' -import { TopNavigation } from 'app/(admin)/components/TopNavigation' -import { cookies } from 'next/headers' import { ExpandableInfo } from './components/ExpandableInfo' -import { verifySession } from 'app/(admin)/utils/firebase' export const metadata: Metadata = { title: 'Personvern | Entur Tavla', } -async function Privacy() { - const session = cookies().get('session')?.value - const loggedIn = (await verifySession(session)) !== null - +function Privacy() { return ( <> -
Personvern diff --git a/next-tavla/src/Board/scenarios/Board/index.tsx b/next-tavla/src/Board/scenarios/Board/index.tsx index ef6317339..7f5f94251 100644 --- a/next-tavla/src/Board/scenarios/Board/index.tsx +++ b/next-tavla/src/Board/scenarios/Board/index.tsx @@ -19,7 +19,7 @@ function Board({ board, style }: { board: TBoard; style?: CSSProperties }) { if (!board.tiles || !board.tiles.length) return ( -

Du har ikke lagt til noen stoppesteder enda.

+

Du har ikke lagt til noen stoppesteder ennå.

) diff --git a/next-tavla/src/Board/scenarios/Table/index.tsx b/next-tavla/src/Board/scenarios/Table/index.tsx index 95d3a169f..ea064f2c8 100644 --- a/next-tavla/src/Board/scenarios/Table/index.tsx +++ b/next-tavla/src/Board/scenarios/Table/index.tsx @@ -29,7 +29,7 @@ function Table({ if (!columns || !isArray(columns)) return (
- Du har ikke lagt til noen kolonner enda + Du har ikke lagt til noen kolonner ennå
)