chore: organize code structure

This commit is contained in:
crazywoola
2023-06-20 13:50:33 +08:00
parent aa8a185018
commit 89aa13e65d
4 changed files with 14 additions and 8 deletions
+2 -2
View File
@@ -1,13 +1,13 @@
'use client'
import { FC } from 'react'
import { LocaleProps } from '@/interface'
import { LocaleProps, ConversationsProps } from '@/interface'
import Button from '@/components/button'
import PencilSquare from '@heroicons/react/24/solid/PencilSquareIcon'
import MenuItem from '@/components/menu-item'
import { t } from '@/i18n'
const Main: FC<LocaleProps> = ({ locale }) => {
const Main: FC<ConversationsProps & LocaleProps> = ({ locale }) => {
return (
<div className='flex flex-col shrink-0 w-60 h-screen bg-white'>
<div className='flex items-center w-full h-16 p-4'>
+9 -2
View File
@@ -1,11 +1,18 @@
import Main from './main'
import { getLocale, client } from '@/service'
import { ConversationsProps } from '@/interface'
async function getData() {}
async function getData() {
const { status, data } = await client.getConversations()
if (status !== 200) {
throw new Error('Failed to fetch data')
}
return data as ConversationsProps
}
const Sidebar = async () => {
const conversations = await getData()
return <Main locale={getLocale()} />
return <Main locale={getLocale()} {...conversations} />
}
export default Sidebar
-3
View File
@@ -3,9 +3,6 @@ import Main from './main'
async function getData() {
const { status, data: appInfo } = await client.getApplicationParameters()
// The return value is *not* serialized
// You can return Date, Map, Set, etc.
// Recommendation: handle errors
if (status !== 200) {
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
+3 -1
View File
@@ -23,5 +23,7 @@ export interface ConversationProps {
}
export interface ConversationsProps {
conversations: ConversationProps[]
data: ConversationProps[]
has_more: boolean
limit: number
}