feat(Documents Filter): Keep the URL and UI state in sync when status filter changes

This commit is contained in:
Subham Ray
2023-04-24 19:16:56 +05:30
parent ab96990d43
commit dc6217b14e

View File

@ -83,6 +83,20 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
return filteredDocuments;
}
function handleSetSelectedStatusFilter(status: any) {
router.replace(
{
pathname: router.pathname,
query: { filter: status.value },
},
undefined,
{
shallow: true, // Perform a shallow update, without reloading the page
}
);
setSelectedStatusFilter(status);
}
function wasXDaysAgoOrLess(documentDate: Date, lastXDays: number): boolean {
if (lastXDays < 0) return true;
@ -138,7 +152,7 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
label="Status"
options={statusFilters}
value={selectedStatusFilter}
onChange={setSelectedStatusFilter}
onChange={handleSetSelectedStatusFilter}
/>
</div>
<div className="mt-20 max-w-[1100px]" hidden={!loading}>