Fixed the cookie issue (i think)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
} from '@/components/ui/chart';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
const chartConfig = {
|
||||
views: {
|
||||
@@ -29,7 +30,7 @@ export default function Engagement({
|
||||
chartData: {
|
||||
week: string;
|
||||
views: number;
|
||||
}[];
|
||||
}[] | null;
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
@@ -40,60 +41,66 @@ export default function Engagement({
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ChartContainer
|
||||
config={chartConfig}
|
||||
className="w-full xl:w-[680px] lg:h-[270px] 2xl:w-[880px]"
|
||||
>
|
||||
<AreaChart
|
||||
accessibilityLayer
|
||||
data={chartData}
|
||||
margin={{
|
||||
left: 12,
|
||||
right: 12,
|
||||
}}
|
||||
{chartData ? (
|
||||
<ChartContainer
|
||||
config={chartConfig}
|
||||
className="w-full xl:w-[680px] lg:h-[270px] 2xl:w-[880px]"
|
||||
>
|
||||
<CartesianGrid vertical={false} />
|
||||
<XAxis
|
||||
dataKey="week"
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
tickFormatter={(value) => value.slice(0, 3)}
|
||||
/>
|
||||
<ChartTooltip
|
||||
cursor={false}
|
||||
content={<ChartTooltipContent indicator="line" />}
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="fillViews"
|
||||
x1="0"
|
||||
y1="0"
|
||||
x2="0"
|
||||
y2="1"
|
||||
>
|
||||
<stop
|
||||
offset="5%"
|
||||
stopColor="var(--color-views)"
|
||||
stopOpacity={0.8}
|
||||
/>
|
||||
<stop
|
||||
offset="95%"
|
||||
stopColor="var(--color-views)"
|
||||
stopOpacity={0.1}
|
||||
/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<AreaChart
|
||||
accessibilityLayer
|
||||
data={chartData}
|
||||
margin={{
|
||||
left: 12,
|
||||
right: 12,
|
||||
}}
|
||||
>
|
||||
<CartesianGrid vertical={false} />
|
||||
<XAxis
|
||||
dataKey="week"
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
tickFormatter={(value) => value.slice(0, 3)}
|
||||
/>
|
||||
<ChartTooltip
|
||||
cursor={false}
|
||||
content={
|
||||
<ChartTooltipContent indicator="line" />
|
||||
}
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="fillViews"
|
||||
x1="0"
|
||||
y1="0"
|
||||
x2="0"
|
||||
y2="1"
|
||||
>
|
||||
<stop
|
||||
offset="5%"
|
||||
stopColor="var(--color-views)"
|
||||
stopOpacity={0.8}
|
||||
/>
|
||||
<stop
|
||||
offset="95%"
|
||||
stopColor="var(--color-views)"
|
||||
stopOpacity={0.1}
|
||||
/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<Area
|
||||
dataKey="views"
|
||||
type="natural"
|
||||
fill="url(#fillViews)"
|
||||
fillOpacity={0.4}
|
||||
stroke="var(--color-views)"
|
||||
/>
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
<Area
|
||||
dataKey="views"
|
||||
type="natural"
|
||||
fill="url(#fillViews)"
|
||||
fillOpacity={0.4}
|
||||
stroke="var(--color-views)"
|
||||
/>
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
) : (
|
||||
<Skeleton className="w-full xl:w-[680px] lg:h-[270px] 2xl:w-[880px]" />
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
+22
-20
@@ -1,32 +1,34 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import AccountStatus from './accountStatus';
|
||||
import Engagement from './engagement';
|
||||
import Ideas from './ideas';
|
||||
import RecentPosts from './recentPosts';
|
||||
import App from '@/components/app';
|
||||
import { Calendar } from '@/components/ui/calendar';
|
||||
import { cookies } from 'next/headers';
|
||||
import axios from 'axios';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
async function getSession(sessionId: string) {
|
||||
try {
|
||||
return (
|
||||
await axios.get(`http://localhost:3000/api/session/?id=${sessionId}`)
|
||||
).data.dashboard;
|
||||
} catch {
|
||||
redirect('/login');
|
||||
}
|
||||
}
|
||||
export default function Dashboard() {
|
||||
const [data, setData] = useState({
|
||||
engagement: null,
|
||||
ideas: [],
|
||||
accounts: [],
|
||||
posts: [],
|
||||
});
|
||||
const router = useRouter();
|
||||
|
||||
export default async function Dashboard() {
|
||||
const cookieStore = await cookies();
|
||||
const sessionId = cookieStore.get('session_id')?.value || '';
|
||||
|
||||
const data = await getSession(sessionId);
|
||||
|
||||
if (!data) {
|
||||
return '';
|
||||
}
|
||||
useEffect(() => {
|
||||
axios
|
||||
.get('/api/session/')
|
||||
.then((res) => {
|
||||
setData(res.data.dashboard);
|
||||
})
|
||||
.catch(() => {
|
||||
router.push('/login');
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<App>
|
||||
|
||||
Reference in New Issue
Block a user