mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
rework sidemenu + fix no categories / links
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import Input from '../../components/input';
|
||||
import styles from '../../styles/create.module.scss';
|
||||
|
||||
import { Category } from '../../types';
|
||||
import { BuildCategory } from '..';
|
||||
import { BuildCategory } from '../../utils/front';
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import Selector from '../../components/selector';
|
||||
|
||||
Reference in New Issue
Block a user