WeedChat
This commit is contained in:
parent
6dae0db7dc
commit
38eb166953
@ -8,6 +8,12 @@ const menuAside: MenuAsideItem[] = [
|
||||
label: 'Dashboard',
|
||||
},
|
||||
|
||||
{
|
||||
href: '/timeline',
|
||||
icon: icon.mdiViewDashboard,
|
||||
label: 'Timeline',
|
||||
},
|
||||
|
||||
{
|
||||
href: '/users/users-list',
|
||||
label: 'Users',
|
||||
@ -42,7 +48,7 @@ const menuAside: MenuAsideItem[] = [
|
||||
},
|
||||
{
|
||||
href: '/timeline_posts/timeline_posts-list',
|
||||
label: 'Timeline posts',
|
||||
label: 'Timeline posts (Admin)',
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
icon: 'mdiPostOutline' in icon ? icon['mdiPostOutline' as keyof typeof icon] : icon.mdiTable ?? icon.mdiTable,
|
||||
@ -136,4 +142,4 @@ const menuAside: MenuAsideItem[] = [
|
||||
},
|
||||
]
|
||||
|
||||
export default menuAside
|
||||
export default menuAside
|
||||
72
frontend/src/pages/timeline.tsx
Normal file
72
frontend/src/pages/timeline.tsx
Normal file
@ -0,0 +1,72 @@
|
||||
import { mdiViewDashboard, mdiPlus } from '@mdi/js';
|
||||
import Head from 'next/head';
|
||||
import React, { ReactElement, useEffect, useState } from 'react';
|
||||
import CardBox from '../components/CardBox';
|
||||
import LayoutAuthenticated from '../layouts/Authenticated';
|
||||
import SectionMain from '../components/SectionMain';
|
||||
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton';
|
||||
import FormField from '../components/FormField';
|
||||
import BaseButton from '../components/BaseButton';
|
||||
import { useAppDispatch, useAppSelector } from '../stores/hooks';
|
||||
import { fetch, create } from '../stores/timeline_posts/timeline_postsSlice';
|
||||
import { getPageTitle } from '../config';
|
||||
|
||||
const TimelinePage = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const { timeline_posts, loading } = useAppSelector((state) => state.timeline_posts);
|
||||
const [content, setContent] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetch({}));
|
||||
}, [dispatch]);
|
||||
|
||||
const handlePost = () => {
|
||||
if (!content.trim()) return;
|
||||
dispatch(create({ content })).then(() => {
|
||||
setContent('');
|
||||
dispatch(fetch({}));
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{getPageTitle('Timeline')}</title>
|
||||
</Head>
|
||||
<SectionMain>
|
||||
<SectionTitleLineWithButton icon={mdiViewDashboard} title="Timeline" main />
|
||||
|
||||
<CardBox className="mb-6">
|
||||
<FormField label="What's on your mind?">
|
||||
<textarea
|
||||
className="w-full p-2 border border-gray-300 rounded"
|
||||
rows={3}
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
/>
|
||||
</FormField>
|
||||
<BaseButton label="Post" color="info" onClick={handlePost} icon={mdiPlus} />
|
||||
</CardBox>
|
||||
|
||||
<div className="space-y-4">
|
||||
{loading ? (
|
||||
<p>Loading posts...</p>
|
||||
) : (
|
||||
timeline_posts.map((post: any) => (
|
||||
<CardBox key={post.id}>
|
||||
<p className="text-gray-800">{post.content}</p>
|
||||
<small className="text-gray-500">{new Date(post.createdAt).toLocaleString()}</small>
|
||||
</CardBox>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</SectionMain>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
TimelinePage.getLayout = function getLayout(page: ReactElement) {
|
||||
return <LayoutAuthenticated>{page}</LayoutAuthenticated>;
|
||||
};
|
||||
|
||||
export default TimelinePage;
|
||||
Loading…
x
Reference in New Issue
Block a user