mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-16 20:59:27 +00:00
feat: apply layout
This commit is contained in:
@@ -44,6 +44,7 @@ type Props = {
|
|||||||
onDeleteClick: (id: string) => void
|
onDeleteClick: (id: string) => void
|
||||||
onEditClick: (id: string) => void
|
onEditClick: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DecksTable = ({ currentUserId, decks, onDeleteClick, onEditClick }: Props) => {
|
export const DecksTable = ({ currentUserId, decks, onDeleteClick, onEditClick }: Props) => {
|
||||||
const handleEditClick = (id: string) => () => onEditClick(id)
|
const handleEditClick = (id: string) => () => onEditClick(id)
|
||||||
const handleDeleteClick = (id: string) => () => onDeleteClick(id)
|
const handleDeleteClick = (id: string) => () => onDeleteClick(id)
|
||||||
|
|||||||
@@ -16,13 +16,17 @@ import {
|
|||||||
import s from './user-dropdown.module.scss'
|
import s from './user-dropdown.module.scss'
|
||||||
|
|
||||||
export type UserDropdownProps = {
|
export type UserDropdownProps = {
|
||||||
avatar: string
|
avatar: null | string
|
||||||
email: string
|
email: string
|
||||||
onLogout: ComponentPropsWithoutRef<typeof DropdownMenuItem>['onSelect']
|
onLogout: ComponentPropsWithoutRef<typeof DropdownMenuItem>['onSelect']
|
||||||
userName: string
|
userName: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserDropdown = ({ avatar, email, onLogout, userName }: UserDropdownProps) => {
|
export const UserDropdown = ({ avatar, email, onLogout, userName }: UserDropdownProps) => {
|
||||||
|
if (!avatar) {
|
||||||
|
avatar = `https://ui-avatars.com/api/?name=${userName.split(' ').join('+')}`
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import type { Meta, StoryObj } from '@storybook/react'
|
import type { Meta, StoryObj } from '@storybook/react'
|
||||||
|
|
||||||
import { Layout } from './'
|
import { LayoutPrimitive } from './'
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
argTypes: {
|
argTypes: {
|
||||||
onLogout: { action: 'logout' },
|
onLogout: { action: 'logout' },
|
||||||
},
|
},
|
||||||
component: Layout,
|
component: LayoutPrimitive,
|
||||||
parameters: {
|
parameters: {
|
||||||
layout: 'fullscreen',
|
layout: 'fullscreen',
|
||||||
},
|
},
|
||||||
tags: ['autodocs'],
|
tags: ['autodocs'],
|
||||||
title: 'Components/Layout',
|
title: 'Components/Layout',
|
||||||
} satisfies Meta<typeof Layout>
|
} satisfies Meta<typeof LayoutPrimitive>
|
||||||
|
|
||||||
export default meta
|
export default meta
|
||||||
type Story = StoryObj<typeof meta>
|
type Story = StoryObj<typeof meta>
|
||||||
|
|||||||
@@ -1,12 +1,34 @@
|
|||||||
import { ReactNode } from 'react'
|
import { ReactNode } from 'react'
|
||||||
|
import { Outlet } from 'react-router-dom'
|
||||||
|
|
||||||
import { Header, HeaderProps } from '@/components'
|
import { Header, HeaderProps } from '@/components'
|
||||||
|
import { useMeQuery } from '@/services/auth/auth.service'
|
||||||
|
|
||||||
import s from './layout.module.scss'
|
import s from './layout.module.scss'
|
||||||
|
|
||||||
export type LayoutProps = { children: ReactNode } & HeaderProps
|
export const Layout = () => {
|
||||||
|
const { data, isError, isLoading } = useMeQuery()
|
||||||
|
|
||||||
export const Layout = ({ children, ...headerProps }: LayoutProps) => {
|
if (isLoading) {
|
||||||
|
return <div>loading...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LayoutPrimitive
|
||||||
|
avatar={data?.avatar ?? null}
|
||||||
|
email={data?.email ?? ''}
|
||||||
|
isLoggedIn={!isError && !!data}
|
||||||
|
onLogout={() => {}}
|
||||||
|
userName={data?.name ?? ''}
|
||||||
|
>
|
||||||
|
<Outlet />
|
||||||
|
</LayoutPrimitive>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LayoutPrimitiveProps = { children: ReactNode } & HeaderProps
|
||||||
|
|
||||||
|
export const LayoutPrimitive = ({ children, ...headerProps }: LayoutPrimitiveProps) => {
|
||||||
return (
|
return (
|
||||||
<div className={s.layout}>
|
<div className={s.layout}>
|
||||||
<Header {...headerProps} />
|
<Header {...headerProps} />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.root {
|
.root {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
margin-top: 36px;
|
margin-top: 36px;
|
||||||
padding-inline: 24px;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
createBrowserRouter,
|
createBrowserRouter,
|
||||||
} from 'react-router-dom'
|
} from 'react-router-dom'
|
||||||
|
|
||||||
|
import { Layout } from '@/components/layout'
|
||||||
import { DeckPage } from '@/pages/deck-page/deck-page'
|
import { DeckPage } from '@/pages/deck-page/deck-page'
|
||||||
|
|
||||||
import { DecksPage, SignInPage } from './pages'
|
import { DecksPage, SignInPage } from './pages'
|
||||||
@@ -36,10 +37,15 @@ const privateRoutes: RouteObject[] = [
|
|||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
children: privateRoutes,
|
children: [
|
||||||
element: <PrivateRoutes />,
|
{
|
||||||
|
children: privateRoutes,
|
||||||
|
element: <PrivateRoutes />,
|
||||||
|
},
|
||||||
|
...publicRoutes,
|
||||||
|
],
|
||||||
|
element: <Layout />,
|
||||||
},
|
},
|
||||||
...publicRoutes,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
export const Router = () => {
|
export const Router = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user