diff --git a/src/client/dd-hub-react/src/api/document-service.ts b/src/client/dd-hub-react/src/api/document-service.ts index 3b049e9..ec6fc4b 100644 --- a/src/client/dd-hub-react/src/api/document-service.ts +++ b/src/client/dd-hub-react/src/api/document-service.ts @@ -15,14 +15,14 @@ export type DocQuery = { name?: string | undefined } -export function getDocuments({ id, name }: DocQuery): Promise { +export function getDocuments(query: DocQuery | undefined = undefined): Promise { let documents = _documents; - if (id) - documents = documents.filter(d => d.id = id) + if (query?.id) + documents = documents.filter(d => d.id === query.id); - if (name) - documents = documents.filter(d => d.name = name) + if (query?.name) + documents = documents.filter(d => d.name === query.name); return Promise.resolve(documents); } diff --git a/src/client/dd-hub-react/src/pages/doc-search.tsx b/src/client/dd-hub-react/src/pages/doc-search.tsx index c0002dd..0fa4e59 100644 --- a/src/client/dd-hub-react/src/pages/doc-search.tsx +++ b/src/client/dd-hub-react/src/pages/doc-search.tsx @@ -1,16 +1,27 @@ +import { useEffect, useState } from 'react'; + import { _posts } from 'src/_mock'; import { CONFIG } from 'src/config-global'; +import { Doc, getDocuments } from 'src/api/document-service'; import { DocSearchView } from 'src/sections/document/view'; // ---------------------------------------------------------------------- export default function Page() { + const [docs, setDocs] = useState([]); + + useEffect(() => { + getDocuments({}).then((res) => { + setDocs(res); + }); + }, []); + return ( <> {`Document Search - ${CONFIG.appName}`} - + ); } diff --git a/src/client/dd-hub-react/src/sections/document/doc-item.tsx b/src/client/dd-hub-react/src/sections/document/doc-item.tsx index 2d7d609..fd54ce7 100644 --- a/src/client/dd-hub-react/src/sections/document/doc-item.tsx +++ b/src/client/dd-hub-react/src/sections/document/doc-item.tsx @@ -10,202 +10,187 @@ import Avatar from '@mui/material/Avatar'; import Typography from '@mui/material/Typography'; import { fDate } from 'src/utils/format-time'; -import { fShortenNumber } from 'src/utils/format-number'; + +import { Doc } from 'src/api/document-service'; import { Iconify } from 'src/components/iconify'; import { SvgColor } from 'src/components/svg-color'; // ---------------------------------------------------------------------- -export type IDocItem = { - id: string; - title: string; - coverUrl: string; - totalViews: number; - description: string; - totalShares: number; - totalComments: number; - totalFavorites: number; - postedAt: string | number | null; - author: { - name: string; - avatarUrl: string; - }; -}; - export function DocItem({ - sx, - doc, - long, - large, - ...other + sx, + doc, + long, + large, + ...other }: CardProps & { - doc: IDocItem; - long: boolean; - large: boolean; + doc: Doc; + long: boolean; + large: boolean; }) { - const renderAvatar = ( - - ); + const renderAvatar = ( + + ); - const renderTitle = ( - - {doc.title} - - ); - - const renderInfo = ( - - {[ - { number: doc.totalComments, icon: 'solar:chat-round-dots-bold' }, - { number: doc.totalViews, icon: 'solar:eye-bold' }, - { number: doc.totalShares, icon: 'solar:share-bold' }, - ].map((info, _index) => ( - - - {fShortenNumber(info.number)} + {doc.name} + + ); + + const renderInfo = ( + + {[ + { data: doc.addedWho, icon: 'solar:chat-round-dots-bold' }, + { data: doc.changedWho, icon: 'solar:eye-bold' }, + { data: doc.changedWhen, icon: 'solar:share-bold' }, + ].map((info, _index) => ( + + + {info.data?.toString()} + + ))} - ))} - - ); + ); - const renderCover = ( - - ); + const renderCover = ( + + ); - const renderDate = ( - - {fDate(doc.postedAt)} - - ); + const renderDate = ( + + {fDate(doc.addedWhen)} + + ); - const renderShape = ( - - ); + const renderShape = ( + + ); - return ( - - ({ - position: 'relative', - pt: 'calc(100% * 3 / 4)', - ...((large || long) && { - pt: 'calc(100% * 4 / 3)', - '&:after': { - top: 0, - content: "''", - width: '100%', - height: '100%', - position: 'absolute', - bgcolor: varAlpha(theme.palette.grey['900Channel'], 0.72), - }, - }), - ...(large && { - pt: { - xs: 'calc(100% * 4 / 3)', - sm: 'calc(100% * 3 / 4.66)', - }, - }), - })} - > - {renderShape} - {renderAvatar} - {renderCover} - + return ( + + ({ + position: 'relative', + pt: 'calc(100% * 3 / 4)', + ...((large || long) && { + pt: 'calc(100% * 4 / 3)', + '&:after': { + top: 0, + content: "''", + width: '100%', + height: '100%', + position: 'absolute', + bgcolor: varAlpha(theme.palette.grey['900Channel'], 0.72), + }, + }), + ...(large && { + pt: { + xs: 'calc(100% * 4 / 3)', + sm: 'calc(100% * 3 / 4.66)', + }, + }), + })} + > + {renderShape} + {renderAvatar} + {renderCover} + - ({ - p: theme.spacing(6, 3, 3, 3), - ...((large || long) && { - width: 1, - bottom: 0, - position: 'absolute', - }), - })} - > - {renderDate} - {renderTitle} - {renderInfo} - - - ); + ({ + p: theme.spacing(6, 3, 3, 3), + ...((large || long) && { + width: 1, + bottom: 0, + position: 'absolute', + }), + })} + > + {renderDate} + {renderTitle} + {renderInfo} + + + ); } diff --git a/src/client/dd-hub-react/src/sections/document/doc-search.tsx b/src/client/dd-hub-react/src/sections/document/doc-search.tsx index 4d4d753..019695e 100644 --- a/src/client/dd-hub-react/src/sections/document/doc-search.tsx +++ b/src/client/dd-hub-react/src/sections/document/doc-search.tsx @@ -4,14 +4,14 @@ import TextField from '@mui/material/TextField'; import InputAdornment from '@mui/material/InputAdornment'; import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete'; -import { Iconify } from 'src/components/iconify'; +import { Doc } from 'src/api/document-service'; -import type { IDocItem } from './doc-item'; +import { Iconify } from 'src/components/iconify'; // ---------------------------------------------------------------------- type DocSearchProps = { - posts: IDocItem[]; + posts: Doc[]; sx?: SxProps; }; @@ -33,7 +33,7 @@ export function DocSearch({ posts, sx }: DocSearchProps) { }, }} options={posts} - getOptionLabel={(post) => post.title} + getOptionLabel={(post) => post.name} isOptionEqualToValue={(option, value) => option.id === value.id} renderInput={(params) => ( ([]) @@ -51,7 +50,7 @@ export function DocSearchView({ posts }: Props) { // justifyContent: 'space-between', // }} // > - // + // // - {posts.map((post, index) => { + {docs.map((doc, index) => { const large = false; const long = false; return ( - + ); })}