Skip to content

Commit

Permalink
Allowed filters for cretain pages, added two new filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Nov 3, 2023
1 parent f42315f commit 2cf9af6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Website/src/activitys/fragments/ModuleFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,24 @@ const ModuleFragment = React.memo<ModuleFragmentProps>((props) => {
setAnchorEl(null);
}}
>
{filters.map((fil) => (
<MenuItem
onClick={() => {
setFilter(fil.value);
setAnchorEl(null);
}}
disableRipple
>
<fil.icon />
{fil.name}
</MenuItem>
))}
{filters.map((fil) => {
if (fil.allowedIds.includes(props.id)) {
return (
<MenuItem
onClick={() => {
setFilter(fil.value);
setAnchorEl(null);
}}
disableRipple
>
<fil.icon />
{fil.name}
</MenuItem>
);
} else {
return null;
}
})}
</StyledMenu>
</Stack>

Expand Down
22 changes: 22 additions & 0 deletions Website/src/hooks/useModulesFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,52 @@ import ListItemButton from "@mui/material/ListItemButton";
import ListItemText from "@mui/material/ListItemText";
import Dialog from "@mui/material/Dialog";
import DialogTitle from "@mui/material/DialogTitle";
import StarIcon from "@mui/icons-material/Star";
import StarBorderIcon from "@mui/icons-material/StarBorder";
import React from "react";

export const filters = [
{
name: "No filter",
icon: UpdateDisabledIcon,
value: "none",
allowedIds: ["explore", "local"],
},
{
name: "By date (newest)",
icon: CalendarMonthIcon,
value: "date_newest",
allowedIds: ["explore"],
},
{
name: "By date (oldest)",
icon: CalendarMonthIcon,
value: "date_oldest",
allowedIds: ["explore"],
},
{
name: "Alphabetically",
icon: AbcIcon,
value: "alphabetically",
allowedIds: ["explore", "local"],
},
{
name: "Alphabetically (reverse)",
icon: AbcIcon,
value: "alphabetically_reverse",
allowedIds: ["explore", "local"],
},
{
name: "Most stars",
icon: StarIcon,
value: "most_stars",
allowedIds: ["explore"],
},
{
name: "Least stars",
icon: StarBorderIcon,
value: "least_stars",
allowedIds: ["explore"],
},
];

Expand All @@ -51,6 +70,8 @@ export const useModuleFilter = (key: string): [Array<any>, string, SetValue<stri
date_newest: [{ key: "last_update", descending: true }],
alphabetically: [{ key: "name", descending: false }],
alphabetically_reverse: [{ key: "name", descending: true }],
least_stars: [{ key: "stars", descending: false }],
most_stars: [{ key: "stars", descending: true }],
}),
[]
);
Expand All @@ -59,6 +80,7 @@ export const useModuleFilter = (key: string): [Array<any>, string, SetValue<stri
};

interface FilterDialogProps {
id: string;
open: boolean;
selectedValue: string;
onClose: (value: string) => void;
Expand Down

0 comments on commit 2cf9af6

Please sign in to comment.