From 75c855b1eeb51bddc26bdac8ae46a28ccc12848c Mon Sep 17 00:00:00 2001 From: Elfing <106489440+elfing44@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:35:43 +0200 Subject: [PATCH] [skip ci] Feat: Add switch Latest / Popular (#995) * Add switch Latest / Popular * Fix label --- .../accordions/PopularNovels/index.tsx | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/accordions/PopularNovels/index.tsx b/src/components/accordions/PopularNovels/index.tsx index 9cf7779..d13b907 100644 --- a/src/components/accordions/PopularNovels/index.tsx +++ b/src/components/accordions/PopularNovels/index.tsx @@ -4,6 +4,9 @@ import { Stack, ToggleButton, ToggleButtonGroup, + Switch, + FormControlLabel, + FormGroup, } from '@mui/material'; import React, { useEffect, useState, ChangeEvent } from 'react'; import AccordionContainer from '../components/AccordionContainer'; @@ -19,12 +22,16 @@ export default function PopularNovels() { const [loading, setLoading] = useState(false); const [currentIndex, setCurrentIndex] = useState(0); const [maxIndex, setMaxIndex] = useState(0); + const [isLatest, setIsLatest] = useState(true); const fetchNovelsByIndex = (index: number) => { if (plugin && index) { setLoading(true); plugin - .popularNovels(index, { filters: filterValues }) + .popularNovels(index, { + filters: filterValues, + showLatestNovels: isLatest, + }) .then(res => { if (res.length !== 0) { setCurrentIndex(index); @@ -38,6 +45,18 @@ export default function PopularNovels() { } }; + const handleSwitchLatestChange = (event: ChangeEvent) => { + setIsLatest(event.target.checked); + }; + + useEffect(() => { + if (plugin) { + setCurrentIndex(1); + setMaxIndex(1); + fetchNovelsByIndex(1); + } + }, [isLatest]); + useEffect(() => { // Reset when changing plugins. setCurrentIndex(0); @@ -57,7 +76,19 @@ export default function PopularNovels() { }, [plugin]); return ( - + + + + } + label={{isLatest ? 'Latest' : 'Popular'}} + /> +