@@ -3,7 +3,19 @@ import { Searchbar } from "@Components/Searchbar";
33import React from "react" ;
44import { useActivity } from "@Hooks/useActivity" ;
55import { useRepos } from "@Hooks/useRepos" ;
6- import { Box , Pagination , Stack , Typography } from "@mui/material" ;
6+ import Stack from "@mui/material/Stack" ;
7+ import Pagination from "@mui/material/Pagination" ;
8+ import Box from "@mui/material/Box" ;
9+ import Button from "@mui/material/Button" ;
10+ import Dialog from "@mui/material/Dialog" ;
11+ import DialogActions from "@mui/material/DialogActions" ;
12+ import DialogContent from "@mui/material/DialogContent" ;
13+ import DialogTitle from "@mui/material/DialogTitle" ;
14+ import InputLabel from "@mui/material/InputLabel" ;
15+ import OutlinedInput from "@mui/material/OutlinedInput" ;
16+ import MenuItem from "@mui/material/MenuItem" ;
17+ import FormControl from "@mui/material/FormControl" ;
18+ import Select , { SelectChangeEvent } from "@mui/material/Select" ;
719import { useStrings } from "@Hooks/useStrings" ;
820import { usePagination } from "@Hooks/usePagination" ;
921import RepoActivity from "@Activitys/RepoActivity" ;
@@ -30,13 +42,39 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => {
3042 const { isNetworkAvailable } = useNetwork ( ) ;
3143 const [ search , setSearch ] = React . useState ( "" ) ;
3244
33- const applyFilter = props . applyFilter ( modules , search ) ;
45+ const [ open , setOpen ] = React . useState ( false ) ;
46+ const [ exploreFilter , setExploreFilter ] = React . useState < number | string > ( "none" ) ;
47+
48+ const filterSystem = ( ) => {
49+ const applyFilter = props . applyFilter ( modules , search ) ;
50+
51+ switch ( exploreFilter ) {
52+ case "none" :
53+ return applyFilter ;
54+ case "date_oldest" :
55+ return applyFilter . sort ( function ( a , b ) {
56+ var da = new Date ( a . last_update ) . getTime ( ) ;
57+ var db = new Date ( b . last_update ) . getTime ( ) ;
58+
59+ return da - db ;
60+ } ) ;
61+ case "date_newest" :
62+ return applyFilter . sort ( function ( a , b ) {
63+ var da = new Date ( a . last_update ) . getTime ( ) ;
64+ var db = new Date ( b . last_update ) . getTime ( ) ;
65+
66+ return db - da ;
67+ } ) ;
68+ default :
69+ return applyFilter ;
70+ }
71+ } ;
3472
3573 const [ page , setPage ] = React . useState ( 1 ) ;
3674
3775 const PER_PAGE = 20 ;
38- const count = Math . ceil ( applyFilter . length / PER_PAGE ) ;
39- const _DATA = usePagination ( applyFilter , PER_PAGE ) ;
76+ const count = Math . ceil ( filterSystem ( ) . length / PER_PAGE ) ;
77+ const _DATA = usePagination ( filterSystem ( ) , PER_PAGE ) ;
4078
4179 if ( ! isNetworkAvailable ) {
4280 return (
@@ -95,20 +133,20 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => {
95133 ) ;
96134 }
97135
98- // if (modulesLoading) {
99- // return (
100- // <ProgressCircular
101- // indeterminate
102- // style={ {
103- // position: "absolute",
104- // left: "50%",
105- // top: "50%",
106- // WebkitTransform: "translate(-50%, -50%)",
107- // transform: "translate(-50%, -50%)",
108- // }}
109- // />
110- // ) ;
111- // } else {
136+ const handleChange = ( event : SelectChangeEvent < typeof exploreFilter > ) => {
137+ setExploreFilter ( event . target . value ) ;
138+ } ;
139+
140+ const handleClickOpen = ( ) => {
141+ setOpen ( true ) ;
142+ } ;
143+
144+ const handleClose = ( event : React . SyntheticEvent < unknown > , reason ?: string ) => {
145+ if ( reason !== "backdropClick" ) {
146+ setOpen ( false ) ;
147+ }
148+ } ;
149+
112150 return (
113151 < Page
114152 renderToolbar = { props . renderToolbar }
@@ -133,17 +171,58 @@ const ExploreModuleFragment = (props: ExploreModuleProps) => {
133171 } }
134172 >
135173 < Page . RelativeContent >
136- < Searchbar placeholder = { strings . search_modules } onChange = { ( e ) => setSearch ( e . target . value ) } />
174+ < Searchbar onFilterClick = { handleClickOpen } placeholder = { strings . search_modules } onChange = { ( e ) => setSearch ( e . target . value ) } />
137175
138176 < Stack sx = { { mt : 1 } } direction = "column" justifyContent = "flex-start" alignItems = "center" spacing = { 1 } >
139177 { _DATA . currentData ( ) . map ( ( module , index ) => (
140178 < ExploreModule index = { index } key = { module . id + index } moduleProps = { module } />
141179 ) ) }
142180 </ Stack >
143181 </ Page . RelativeContent >
182+
183+ < Dialog disableEscapeKeyDown open = { open } onClose = { handleClose } >
184+ < DialogTitle > Apply a filter</ DialogTitle >
185+ < DialogContent >
186+ < Box component = "form" sx = { { display : "flex" , flexWrap : "wrap" } } >
187+ < FormControl sx = { { m : 1 , minWidth : 120 } } >
188+ < InputLabel id = "demo-dialog-select-label" > Filter</ InputLabel >
189+ < Select
190+ labelId = "demo-dialog-select-label"
191+ id = "demo-dialog-select"
192+ value = { exploreFilter }
193+ onChange = { handleChange }
194+ input = { < OutlinedInput label = "Filter" /> }
195+ >
196+ < MenuItem value = "none" >
197+ < em > No filter</ em >
198+ </ MenuItem >
199+ < MenuItem value = "date_oldest" > By date (oldest)</ MenuItem >
200+ < MenuItem value = "date_newest" > By date (newest)</ MenuItem >
201+ </ Select >
202+ </ FormControl >
203+ </ Box >
204+ </ DialogContent >
205+ < DialogActions >
206+ < Button
207+ sx = { {
208+ color : scheme [ 500 ] ,
209+ } }
210+ onClick = { handleClose }
211+ >
212+ Cancel
213+ </ Button >
214+ < Button
215+ sx = { {
216+ color : scheme [ 500 ] ,
217+ } }
218+ onClick = { handleClose }
219+ >
220+ Apply
221+ </ Button >
222+ </ DialogActions >
223+ </ Dialog >
144224 </ Page >
145225 ) ;
146- // }
147226} ;
148227
149228export default ExploreModuleFragment ;
0 commit comments