Skip to content

Commit

Permalink
feat: save recent agendas filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
yumincho committed May 30, 2024
1 parent baf988d commit efbff8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/web/src/components/atoms/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { bg, colors, h, margin, round, row, text, w } from "@biseo/web/styles";
import React from "react";

interface ToggleSwitchProps {
defaultValue: boolean;
handleToggle: () => void;
label: string;
}

export const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
defaultValue,
handleToggle,
label,
}) => (
Expand All @@ -15,6 +17,7 @@ export const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
type="checkbox"
id="toggle"
onChange={handleToggle}
checked={defaultValue}
css={[
w(0),
h(0),
Expand Down
8 changes: 7 additions & 1 deletion packages/web/src/components/molecules/AgendaCard/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import { EmptyAgendaCard } from "./EmptyAgendaCard";

interface Props extends PropsWithChildren {
agendaStatus: AgendaStatus;
recentOnly?: boolean;
handleRecentOnly?: () => void;
}

export const Group: React.FC<Props> = ({
agendaStatus,
recentOnly = false,
handleRecentOnly = () => {},
children = null,
}) => (
Expand All @@ -50,7 +52,11 @@ export const Group: React.FC<Props> = ({
</div>
</div>
{agendaStatus === "terminated" && (
<ToggleSwitch label="최근 투표만" handleToggle={handleRecentOnly} />
<ToggleSwitch
label="최근 투표만"
defaultValue={recentOnly}
handleToggle={handleRecentOnly}
/>
)}
</div>
{Children.count(children) ? (
Expand Down
13 changes: 11 additions & 2 deletions packages/web/src/components/organisms/AgendaSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const gridLayout = css`
`;

export const AgendaSection: React.FC = () => {
const [showRecentAgendasOnly, setShowRecentAgendasOnly] = useState(false);
const [showRecentAgendasOnly, setShowRecentAgendasOnly] = useState(
localStorage.getItem("showRecentAgendasOnly") === "true",
);

const { preparingAgendas, ongoingAgendas, terminatedAgendas } = useAgenda(
state => ({
Expand Down Expand Up @@ -88,7 +90,14 @@ export const AgendaSection: React.FC = () => {
</AgendaCard.Group>
<AgendaCard.Group
agendaStatus="terminated"
handleRecentOnly={() => setShowRecentAgendasOnly(curr => !curr)}
recentOnly={showRecentAgendasOnly}
handleRecentOnly={() => {
setShowRecentAgendasOnly(curr => !curr);
localStorage.setItem(
"showRecentAgendasOnly",
String(!showRecentAgendasOnly),
);
}}
>
{getAgendaCards("terminated")}
</AgendaCard.Group>
Expand Down

0 comments on commit efbff8f

Please sign in to comment.