diff --git a/packages/web/src/components/atoms/ToggleSwitch.tsx b/packages/web/src/components/atoms/ToggleSwitch.tsx new file mode 100644 index 00000000..f86338d1 --- /dev/null +++ b/packages/web/src/components/atoms/ToggleSwitch.tsx @@ -0,0 +1,52 @@ +import { bg, colors, h, margin, round, row, text, w } from "@biseo/web/styles"; +import React from "react"; + +interface ToggleSwitchProps { + handleToggle: () => void; + label: string; +} + +export const ToggleSwitch: React.FC = ({ + handleToggle, + label, +}) => ( +
+ + +
+); diff --git a/packages/web/src/components/molecules/AgendaCard/Group.tsx b/packages/web/src/components/molecules/AgendaCard/Group.tsx index 807065b8..609c2192 100644 --- a/packages/web/src/components/molecules/AgendaCard/Group.tsx +++ b/packages/web/src/components/molecules/AgendaCard/Group.tsx @@ -7,6 +7,7 @@ import { column, gap, h, + justify, padding, round, row, @@ -15,29 +16,42 @@ import { } from "@biseo/web/styles"; import type { AgendaStatus } from "@biseo/interface/agenda"; import { agendaStatusNames } from "@biseo/web/constants/phrases"; +import { ToggleSwitch } from "@biseo/web/components/atoms/ToggleSwitch"; import { EmptyAgendaCard } from "./EmptyAgendaCard"; interface Props extends PropsWithChildren { agendaStatus: AgendaStatus; + handleRecentOnly?: () => void; } -export const Group: React.FC = ({ agendaStatus, children = null }) => ( +export const Group: React.FC = ({ + agendaStatus, + handleRecentOnly = () => {}, + children = null, +}) => (
-
-

{agendaStatusNames[agendaStatus]}

-
- {Children.count(children)} +
+
+

+ {agendaStatusNames[agendaStatus]} +

+
+ {Children.count(children)} +
+ {agendaStatus === "terminated" && ( + + )}
{Children.count(children) ? (
    {children}
diff --git a/packages/web/src/components/organisms/AgendaSection.tsx b/packages/web/src/components/organisms/AgendaSection.tsx index f3c2f4e5..60a46aad 100644 --- a/packages/web/src/components/organisms/AgendaSection.tsx +++ b/packages/web/src/components/organisms/AgendaSection.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from "react"; +import React, { useCallback, useState } from "react"; import type { AgendaStatus } from "@biseo/interface/agenda"; import { AgendaCard } from "@biseo/web/components/molecules"; import { useAgenda } from "@biseo/web/services/agenda"; @@ -37,6 +37,8 @@ const gridLayout = css` `; export const AgendaSection: React.FC = () => { + const [showRecentAgendasOnly, setShowRecentAgendasOnly] = useState(false); + const { preparingAgendas, ongoingAgendas, terminatedAgendas } = useAgenda( state => ({ preparingAgendas: state.agendas.filter(isPreparingAgenda), @@ -48,8 +50,18 @@ export const AgendaSection: React.FC = () => { const getAgendas = useCallback( (agendaStatus: AgendaStatus) => { if (agendaStatus === "preparing") return preparingAgendas; - if (agendaStatus === "ongoing") return ongoingAgendas; - if (agendaStatus === "terminated") return terminatedAgendas; + if (agendaStatus === "ongoing") + return ongoingAgendas.sort((a, b) => a.voters.voted - b.voters.voted); + + if (agendaStatus === "terminated") { + const recent24Hours = new Date(); + recent24Hours.setDate(new Date().getDate() - 1); + return showRecentAgendasOnly + ? terminatedAgendas.filter( + agenda => new Date(agenda.endAt) > recent24Hours, + ) + : terminatedAgendas; + } return []; }, [preparingAgendas, ongoingAgendas, terminatedAgendas], @@ -58,13 +70,6 @@ export const AgendaSection: React.FC = () => { const getAgendaCards = useCallback( (agendaStatus: AgendaStatus) => { const agendas = getAgendas(agendaStatus); - if (agendaStatus === "ongoing") { - agendas.sort((a, b) => { - if (a.voters.voted === 0) return -1; - if (b.voters.voted === 0) return 1; - return 0; - }); - } return agendas.map(agenda => ( )); @@ -81,7 +86,10 @@ export const AgendaSection: React.FC = () => { {getAgendaCards("preparing")} - + setShowRecentAgendasOnly(curr => !curr)} + > {getAgendaCards("terminated")}