Skip to content

Commit 5d5e4ef

Browse files
committed
refactor: split in two views, compete link and default
1 parent 7178c20 commit 5d5e4ef

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

app/compete/page.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fetchTemplates from '../../actions/fetchTemplates';
2+
import StartForm from '../../components/forms/StartForm';
3+
4+
export default async function Page() {
5+
const templates = await fetchTemplates();
6+
return <StartForm templates={templates}></StartForm>;
7+
}

app/page.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import fetchTemplates from '../actions/fetchTemplates';
2-
import TemplateForm from '../components/templates/TemplateForm';
1+
import StartForm from '../components/forms/StartForm';
2+
import { TemplateInformations, templatesDictionary } from '../config/templates';
33

44
export default async function Page() {
5-
const templates = await fetchTemplates();
6-
return <TemplateForm templates={templates}></TemplateForm>;
5+
const templates: TemplateInformations[] = Object.entries(
6+
templatesDictionary
7+
).map(([key, value]) => ({
8+
...value,
9+
eventName: key,
10+
}));
11+
return <StartForm templates={templates}></StartForm>;
712
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { TemplateInformations } from '../../config/templates';
2+
3+
import { useFetchTemplates } from '../../hooks/useFetchTemplates';
4+
import StartForm from './StartForm';
5+
6+
export default function CompetitionStartingForm({
7+
templates: newTemplates,
8+
}: {
9+
templates: TemplateInformations[];
10+
}) {
11+
const { templates = newTemplates } = useFetchTemplates();
12+
13+
return <StartForm templates={templates} />;
14+
}

components/templates/TemplateForm.tsx components/forms/StartForm.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@ import { TemplateInformations } from '../../config/templates';
88
import { useEntryStore } from '../../hooks/useEntryStore';
99

1010
import styles from '../../styles/register.module.scss';
11-
import useSWR from 'swr';
12-
import fetchTemplates from '../../actions/fetchTemplates';
1311

14-
export default function TemplateForm({
15-
templates: newTemplates,
12+
export default function StartForm({
13+
templates,
1614
}: {
1715
templates: TemplateInformations[];
1816
}) {
19-
const { data: templates = newTemplates } = useSWR(
20-
'templates',
21-
async () => {
22-
return await fetchTemplates();
23-
},
24-
{
25-
refreshInterval: 2000,
26-
}
27-
);
28-
2917
const router = useRouter();
3018
const [selectedTemplateIndex, setSelectedTemplateIndex] = useState<number>(0);
3119
const { entry, updateFullName, updateId, updateIsLoading, updateTemplate } =

hooks/useFetchTemplates.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use client';
2+
import useSWR from 'swr';
3+
import fetchTemplates from '../actions/fetchTemplates';
4+
5+
export function useFetchTemplates() {
6+
const { data: templates } = useSWR(
7+
'templates',
8+
async () => {
9+
return await fetchTemplates();
10+
},
11+
{
12+
refreshInterval: 2000,
13+
}
14+
);
15+
16+
return { templates };
17+
}

0 commit comments

Comments
 (0)