rework sidemenu + fix no categories / links

This commit is contained in:
Sonny
2022-04-28 18:22:39 +02:00
parent 1ab51979fe
commit 1a5fb2eee4
14 changed files with 309 additions and 853 deletions

View File

@@ -1,10 +1,9 @@
import { createRef, useRef, useState } from 'react';
import { useState } from 'react';
import { useSession } from 'next-auth/react';
import { Provider } from 'react-redux';
import Head from 'next/head'
import Head from 'next/head';
import Categories from '../components/Categories/Categories';
import Links from '../components/Links/Links';
import Menu from '../components/Categories/SideMenu';
import { Category, Link } from '../types';
@@ -12,6 +11,9 @@ import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
import { store } from '../redux';
import { BuildCategory } from '../utils/front';
import Links from '../components/Links/Links';
interface HomeProps {
categories: Category[];
@@ -34,7 +36,7 @@ export default function Home({ categories, favorites }: HomeProps) {
<title>Superpipo</title>
</Head>
<div className='App'>
<Categories
<Menu
categories={categories}
favorites={favorites}
handleSelectCategory={handleSelectCategory}
@@ -57,37 +59,18 @@ export async function getStaticProps() {
return category;
});
if (categories.length === 0) {
return {
redirect: {
destination: '/category/create'
}
}
}
return {
props: {
categories: JSON.parse(JSON.stringify(categories)),
favorites: JSON.parse(JSON.stringify(favorites)),
}
}
}
export function BuildCategory({ id, name, order, links = [], createdAt, updatedAt }): Category {
return {
id,
name,
links: links.map((link) => BuildLink(link, { categoryId: id, categoryName: name })),
order,
createdAt,
updatedAt
}
}
export function BuildLink({ id, name, url, order, favorite, createdAt, updatedAt }, { categoryId, categoryName }): Link {
return {
id,
name,
url,
category: {
id: categoryId,
name: categoryName
},
order,
favorite,
createdAt,
updatedAt
}
}