diff --git a/Website/src/activitys/fragments/ExploreModuleFragment.tsx b/Website/src/activitys/fragments/ExploreModuleFragment.tsx index ee9a797d..01b46789 100644 --- a/Website/src/activitys/fragments/ExploreModuleFragment.tsx +++ b/Website/src/activitys/fragments/ExploreModuleFragment.tsx @@ -3,7 +3,19 @@ import { Searchbar } from "@Components/Searchbar"; import React from "react"; import { useActivity } from "@Hooks/useActivity"; import { useRepos } from "@Hooks/useRepos"; -import { Box, Pagination, Stack, Typography } from "@mui/material"; +import Stack from "@mui/material/Stack"; +import Pagination from "@mui/material/Pagination"; +import Box from "@mui/material/Box"; +import Button from "@mui/material/Button"; +import Dialog from "@mui/material/Dialog"; +import DialogActions from "@mui/material/DialogActions"; +import DialogContent from "@mui/material/DialogContent"; +import DialogTitle from "@mui/material/DialogTitle"; +import InputLabel from "@mui/material/InputLabel"; +import OutlinedInput from "@mui/material/OutlinedInput"; +import MenuItem from "@mui/material/MenuItem"; +import FormControl from "@mui/material/FormControl"; +import Select, { SelectChangeEvent } from "@mui/material/Select"; import { useStrings } from "@Hooks/useStrings"; import { usePagination } from "@Hooks/usePagination"; import RepoActivity from "@Activitys/RepoActivity"; @@ -30,13 +42,39 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => { const { isNetworkAvailable } = useNetwork(); const [search, setSearch] = React.useState(""); - const applyFilter = props.applyFilter(modules, search); + const [open, setOpen] = React.useState(false); + const [exploreFilter, setExploreFilter] = React.useState("none"); + + const filterSystem = () => { + const applyFilter = props.applyFilter(modules, search); + + switch (exploreFilter) { + case "none": + return applyFilter; + case "date_oldest": + return applyFilter.sort(function (a, b) { + var da = new Date(a.last_update).getTime(); + var db = new Date(b.last_update).getTime(); + + return da - db; + }); + case "date_newest": + return applyFilter.sort(function (a, b) { + var da = new Date(a.last_update).getTime(); + var db = new Date(b.last_update).getTime(); + + return db - da; + }); + default: + return applyFilter; + } + }; const [page, setPage] = React.useState(1); const PER_PAGE = 20; - const count = Math.ceil(applyFilter.length / PER_PAGE); - const _DATA = usePagination(applyFilter, PER_PAGE); + const count = Math.ceil(filterSystem().length / PER_PAGE); + const _DATA = usePagination(filterSystem(), PER_PAGE); if (!isNetworkAvailable) { return ( @@ -95,20 +133,20 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => { ); } - // if (modulesLoading) { - // return ( - // - // ); - // } else { + const handleChange = (event: SelectChangeEvent) => { + setExploreFilter(event.target.value); + }; + + const handleClickOpen = () => { + setOpen(true); + }; + + const handleClose = (event: React.SyntheticEvent, reason?: string) => { + if (reason !== "backdropClick") { + setOpen(false); + } + }; + return ( { }} > - setSearch(e.target.value)} /> + setSearch(e.target.value)} /> {_DATA.currentData().map((module, index) => ( @@ -141,9 +179,50 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => { ))} + + + Apply a filter + + + + Filter + + + + + + + + + ); - // } }; export default ExploreModuleFragment; diff --git a/Website/src/components/Searchbar.tsx b/Website/src/components/Searchbar.tsx index 3882c9fc..75671752 100644 --- a/Website/src/components/Searchbar.tsx +++ b/Website/src/components/Searchbar.tsx @@ -5,20 +5,17 @@ import useShadeColor from "../hooks/useShadeColor"; import Paper from "@mui/material/Paper"; import InputBase from "@mui/material/InputBase"; import IconButton from "@mui/material/IconButton"; -import SearchIcon from "@mui/icons-material/Search"; import { useTheme } from "@Hooks/useTheme"; import { useSettings } from "@Hooks/useSettings"; +import FilterListIcon from "@mui/icons-material/FilterList"; type SearchbarProps = { + onFilterClick?: React.MouseEventHandler; onChange: React.ChangeEventHandler; placeholder: string; }; -export const Searchbar = ({ placeholder, onChange }: SearchbarProps) => { - const { scheme } = useTheme(); - const shade = useShadeColor(); - const { settings } = useSettings(); - +export const Searchbar = ({ placeholder, onChange, onFilterClick }: SearchbarProps) => { return ( { width: "100%", }} > - { - // onSearch(value); - // }} - sx={{ p: "10px" }} - aria-label="menu" - > - + +