Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting active state for chosen view #54

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'
import Link from "next/link";
import { useContext } from "react";
import { useContext, useState } from "react";
import { FilterContext } from "@/app/filter-provider";
import { Purchase } from "@prisma/client";
import Analysis from "../Analysis";
Expand All @@ -12,15 +12,16 @@ type SidebarProps = {

export default function Sidebar(props: SidebarProps) {
const { className, purchases } = props;
const [active, setActive] = useState('week');

const context = useContext(FilterContext);

return (
<ul className={className}>
<li className="inline-block md:block uppercase underline mb-2"><Link href="#" onClick={() => context.setPurchaseFilter('week')}>This week</Link></li>
<li className="inline-block md:block uppercase underline mb-2"><Link href="#" onClick={() => context.setPurchaseFilter('month')}>This month</Link></li>
<li className="inline-block md:block uppercase underline mb-2"><Link href="#" onClick={() => context.setPurchaseFilter('year')}>This year</Link></li>
<li className="inline-block md:block uppercase underline mb-2"><Link href="#" onClick={() => context.setPurchaseFilter('all')}>All</Link></li>
<li className={`inline-block md:block uppercase mb-2 ${active == 'week' && 'underline'}`}><Link href="#" onClick={() => { context.setPurchaseFilter('week'); setActive("week")}}>This week</Link></li>
<li className={`inline-block md:block uppercase mb-2 ${active == 'month' && 'underline'}`}><Link href="#" onClick={() => { context.setPurchaseFilter('month'); setActive("month")}}>This month</Link></li>
<li className={`inline-block md:block uppercase mb-2 ${active == 'year' && 'underline'}`}><Link href="#" onClick={() => { context.setPurchaseFilter('year'); setActive("year")}}>This year</Link></li>
<li className={`inline-block md:block uppercase mb-2 ${active == 'all' && 'underline'}`}><Link href="#" onClick={() => { context.setPurchaseFilter('all'); setActive("all")}}>All</Link></li>
<Analysis purchases={purchases} />
</ul>
)
Expand Down