-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
200 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,7 @@ tmp/* | |
.local/ | ||
|
||
# Coverage files | ||
coverage.* | ||
coverage.* | ||
|
||
# Debug files | ||
__debug_bin* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,83 @@ | ||
import { Box, Pagination } from "@mui/material"; | ||
import React from "react"; | ||
import { Box, Pagination, TextField } from '@mui/material'; | ||
import React from 'react'; | ||
|
||
type DAGPaginationProps = { | ||
totalPages: number; | ||
page: number; | ||
pageChange: (page: number) => void; | ||
totalPages: number; | ||
page: number; | ||
pageLimit: number; | ||
pageChange: (page: number) => void; | ||
onPageLimitChange: (pageLimit: number) => void; | ||
}; | ||
|
||
const DAGPagination = ({ totalPages, page, pageChange }: DAGPaginationProps) => { | ||
const handleChange = (event: React.ChangeEvent<unknown>, value: number) => { | ||
pageChange(value); | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
mt: 2, | ||
}} | ||
> | ||
<Pagination | ||
count={totalPages} | ||
page={page} | ||
onChange={handleChange} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
export default DAGPagination; | ||
const DAGPagination = ({ | ||
totalPages, | ||
page, | ||
pageChange, | ||
pageLimit, | ||
onPageLimitChange, | ||
}: DAGPaginationProps) => { | ||
const [inputValue, setInputValue] = React.useState(pageLimit.toString()); | ||
|
||
React.useEffect(() => { | ||
setInputValue(pageLimit.toString()); | ||
}, [pageLimit]); | ||
|
||
const handleChange = (event: React.ChangeEvent<unknown>, value: number) => { | ||
pageChange(value); | ||
}; | ||
|
||
const handleLimitChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const value = event.target.value; | ||
setInputValue(value); | ||
}; | ||
|
||
const commitChange = () => { | ||
const numValue = parseInt(inputValue); | ||
if (!isNaN(numValue) && numValue > 0) { | ||
onPageLimitChange(numValue); | ||
} else { | ||
setInputValue(pageLimit.toString()); | ||
} | ||
}; | ||
|
||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
commitChange(); | ||
event.preventDefault(); | ||
(event.target as HTMLInputElement).blur(); // Remove focus after Enter | ||
} | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
gap: 3, | ||
mt: 2, | ||
}} | ||
> | ||
<TextField | ||
size="small" | ||
label="Items per page" | ||
value={inputValue} | ||
onChange={handleLimitChange} | ||
onBlur={commitChange} | ||
onKeyDown={handleKeyDown} | ||
inputProps={{ | ||
type: 'number', | ||
min: '1', | ||
style: { | ||
width: '100px', | ||
textAlign: 'left', | ||
}, | ||
}} | ||
/> | ||
<Pagination count={totalPages} page={page} onChange={handleChange} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default DAGPagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { createContext, useCallback, useContext, useState } from 'react'; | ||
|
||
export type UserPreferences = { | ||
pageLimit: number; | ||
} | ||
|
||
const UserPreferencesContext = createContext<{ | ||
preferences: UserPreferences; | ||
updatePreference: <K extends keyof UserPreferences>( | ||
key: K, | ||
value: UserPreferences[K] | ||
) => void; | ||
}>(null!); | ||
|
||
|
||
export function UserPreferencesProvider({ children }: { children: React.ReactNode }) { | ||
const [preferences, setPreferences] = useState<UserPreferences>(() => { | ||
try { | ||
const saved = localStorage.getItem('user_preferences'); | ||
return saved ? JSON.parse(saved) : { pageLimit: 50, theme: 'light' }; | ||
} catch { | ||
return { pageLimit: 50, theme: 'light' }; | ||
} | ||
}); | ||
|
||
const updatePreference = useCallback(<K extends keyof UserPreferences>( | ||
key: K, | ||
value: UserPreferences[K] | ||
) => { | ||
setPreferences(prev => { | ||
const next = { ...prev, [key]: value }; | ||
localStorage.setItem('user_preferences', JSON.stringify(next)); | ||
return next; | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<UserPreferencesContext.Provider value={{ preferences, updatePreference }}> | ||
{children} | ||
</UserPreferencesContext.Provider> | ||
); | ||
|
||
} | ||
|
||
export function useUserPreferences() { | ||
return useContext(UserPreferencesContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters