Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Manage views and URLs #126

Merged
merged 40 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
12c9d9a
Create component to allow use NextIntlClientProvider on async components
tomivm Mar 20, 2024
b74f3d9
Make board page an async component implementing the IntlWrapperForAsync
tomivm Mar 20, 2024
10b9f58
create a loading.tsx to @board
tomivm Mar 20, 2024
0b65a73
remove wrong semicolon
tomivm Mar 20, 2024
eafcb04
Create stuff to stash a Dashboard
tomivm Mar 21, 2024
f25a061
Create constants for the STASHED_CONTENT_ID dashboard params
tomivm Mar 21, 2024
0a01da3
Stash Dashboard on rehydration if it Id is equal to STASHED_CONTENT_ID
tomivm Mar 21, 2024
148093f
useSetInitialBoardHook on client Board Container
tomivm Mar 21, 2024
b8d6dba
PreventFetch of Initial board if route is equal to STASHED_CONTENT_ID
tomivm Mar 21, 2024
cf5c1c6
stash board on create
tomivm Mar 22, 2024
149e34a
Replace change board Action by Change Dashboard
tomivm Mar 23, 2024
a6e2ffc
change dashboard on board creation
tomivm Mar 23, 2024
6610c19
Replace the use of changeBoard by changeDashboard
tomivm Mar 23, 2024
51a1c51
detect changes on dashboard Id in dashboard page
tomivm Mar 23, 2024
52b438e
Convert the SavedData component to a pararel route
tomivm Mar 25, 2024
71dd44a
move special files to the SavedData component
tomivm Mar 25, 2024
2d4e22b
Merge remote-tracking branch 'origin/main' into feature/capture-dashb…
tomivm Mar 25, 2024
a391be3
require id's to be string
tomivm Mar 25, 2024
3645349
replace parallel routes for SavedData components
tomivm Mar 25, 2024
73f5d35
Merge branch 'main' into feature/capture-dashboard-url
tomivm Mar 26, 2024
d7e8f42
split useSetInitialBoard in 2 useEffect
tomivm Mar 26, 2024
163bd1d
improve 'useSetDashboardIdOnChange'
tomivm Mar 26, 2024
a11bc70
Create a hook to handle the Dashboard ID change on @savedData component
tomivm Mar 26, 2024
f7b49b7
Create a state to await hydration
tomivm Mar 26, 2024
18d41e7
remove unnecessary prop types for the dashboard
tomivm Mar 26, 2024
3a1266d
preventUseSetBoardOnDashboardIdChange when saved Board edit click
tomivm Mar 27, 2024
da08f36
use a single ref to prevent useSetBoardOnDashboardIdChange
tomivm Mar 27, 2024
3602d7e
Create Action to set board and prompt drom dashboard slice
tomivm Mar 27, 2024
64ed56a
Improve hook to set Dashboard on dashboard Id change
tomivm Mar 27, 2024
8db380d
Manage error on fetch initial board
tomivm Mar 27, 2024
436469d
improve saved Board ids pm fake db
tomivm Mar 27, 2024
b7331de
Merge branch 'main' into feature/capture-dashboard-url
tomivm Mar 27, 2024
41d0664
set initial content from dashboard Id
tomivm Mar 27, 2024
1c997d0
Prevent create a board from a different path than 'create'
tomivm Mar 29, 2024
4de1e5c
improve logic to set the stashedBoard on direct navigation to new path
tomivm Mar 29, 2024
8dab3e8
Implement an accordion for the prompt form UX UI
tomivm Mar 29, 2024
93e51e3
Navigate to initial content on 'New Board' Click
tomivm Mar 31, 2024
e74721c
Add Hover to 'new board' on Accordion
tomivm Mar 31, 2024
b9cf866
merge branch main
tomivm Apr 1, 2024
b333183
Clean prompt before set 'create' view
tomivm Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/app/[locale]/dashboard/[id]/@board/BoardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,63 @@
import InitialContent from './InitialContent';
import BoardContainer from './BoardContainer';
import { useBoundStore } from '@/providers/StoreProvider';
import { useEffect, useState } from 'react';
import { BoardRecord } from '@/commonTypes/Board';
import { useShallow } from 'zustand/react/shallow';
import { INITIAL_CONTENT_ID, STASHED_CONTENT_ID } from '../constants';

export default function BoardPage() {
type RemoteInitialBoard = BoardRecord | null;

const useSetInitialBoard = (
remoteInitialBoard: RemoteInitialBoard,
id: string,
) => {
const [setBoard, stashedDashboard, showInitialContent] = useBoundStore(
useShallow((state) => [
state.setBoard,
state.stashedDashboard,
state.showInitialContent,
]),
);

useEffect(() => {
if (remoteInitialBoard) {
return setBoard(remoteInitialBoard);
}
}, [setBoard, remoteInitialBoard]);

const [initialStashedBoard, setInitialStashedBoard] =
useState<BoardRecord | null>(null);

useEffect(() => {
if (stashedDashboard.board !== null && initialStashedBoard === null) {
setInitialStashedBoard(stashedDashboard.board);
}
}, [stashedDashboard.board, initialStashedBoard]);

useEffect(() => {
if (!remoteInitialBoard && initialStashedBoard) {
if (id === STASHED_CONTENT_ID) return setBoard(initialStashedBoard);
if (id === INITIAL_CONTENT_ID) return showInitialContent();
}
}, [
setBoard,
remoteInitialBoard,
id,
showInitialContent,
initialStashedBoard,
]);
};
export default function BoardPage({
remoteInitialBoard,
id,
}: {
remoteInitialBoard: RemoteInitialBoard;
id: string;
}) {
const shouldDisplayInitialContent = useBoundStore(
useShallow((state) => state.shouldDisplayInitialContent),
);
useSetInitialBoard(remoteInitialBoard, id);
return shouldDisplayInitialContent ? <InitialContent /> : <BoardContainer />;
}
39 changes: 39 additions & 0 deletions src/app/[locale]/dashboard/[id]/@board/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client'; // Error components must be Client Components

import { useRouter } from '@/navigation';
import { useEffect } from 'react';
import Box from '@mui/material/Box';
import { INITIAL_CONTENT_ID } from '@/dashboard/constants';

export default function Error({
error,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
const router = useRouter();
useEffect(() => {
// Log the error to an error reporting service
console.error('err', error);
setTimeout(() => {
router.push(`/dashboard/${INITIAL_CONTENT_ID}`);
}, 2000);
}, [error, router]);

return (
<Box
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
height: '100%',
}}
>
<h1 style={{ color: 'red' }}>ERROR</h1>
<p>{error.message}</p>
<p>you will be redirected to the initial page</p>
</Box>
);
}
35 changes: 28 additions & 7 deletions src/app/[locale]/dashboard/[id]/@board/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { NextIntlClientProvider, useMessages } from 'next-intl';
import BoardDisplayed from './BoardPage';
import pick from 'lodash.pick';
import { BoardRecord } from '@/commonTypes/Board';
import testBoards from '@/dashboard/@board/testBoard.json';
import IntlWrapperForAsync from '@/components/IntlWrapperForAsync/IntlWrapperForAsync';
import { INITIAL_CONTENT_ID, STASHED_CONTENT_ID } from '@/dashboard/constants';

export default function Page() {
const messages = useMessages();
export default async function Page({
params: { id },
}: {
params: { id: string };
}) {
let board: BoardRecord | null = null;

const preventFetch = id === INITIAL_CONTENT_ID || id === STASHED_CONTENT_ID;
if (!preventFetch) {
try {
await fetch('https://postman-echo.com/delay/2', {
cache: 'no-cache',
});
board = testBoards[Number(id)];
if (!board) {
throw new Error('board not found');
}
} catch (error) {
throw error;
}
}

return (
<NextIntlClientProvider messages={pick(messages, 'Board')}>
<BoardDisplayed />
</NextIntlClientProvider>
<IntlWrapperForAsync propertyName="Board">
<BoardDisplayed remoteInitialBoard={board} id={id} />
</IntlWrapperForAsync>
);
}
12 changes: 0 additions & 12 deletions src/app/[locale]/dashboard/[id]/@history/page.tsx

This file was deleted.

Loading