Skip to content

Commit

Permalink
Make model table page persistent through navigation by using sessionS…
Browse files Browse the repository at this point in the history
…torage
  • Loading branch information
monsieurswag committed Apr 5, 2024
1 parent 90c4840 commit f637149
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions frontend/src/lib/components/ModelTable/Pagination.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
<script lang="ts">
import type { DataHandler } from '@vincjo/datatables';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import * as m from '$paraglide/messages';
export let handler: DataHandler;
const pageNumber = handler.getPageNumber();
const pageCount = handler.getPageCount();
const pages = handler.getPages({ ellipsis: true });
let urlModel: string | undefined;
let _sessionStorage = null;
onMount(() => {
_sessionStorage = sessionStorage;
});
$: if ($page.url && _sessionStorage) {
const pageData = JSON.parse(_sessionStorage.getItem("model_table_page_data") ?? "{}");
urlModel = (`${$page.url}`).replace("/\/+$/","").split("/").pop()
const currentPage = pageData[urlModel] ?? 1;
handler.setPage(currentPage);
pageData[urlModel] = currentPage;
_sessionStorage.setItem("model_table_page_data",JSON.stringify(pageData));
}
$: if ($page.url) {
handler.setPage(1);
$: if ($pageNumber && urlModel && _sessionStorage) {
const pageData = JSON.parse(_sessionStorage.getItem("model_table_page_data") ?? "{}");
pageData[urlModel] = $pageNumber;
_sessionStorage.setItem("model_table_page_data",JSON.stringify(pageData));
}
</script>

Expand Down

0 comments on commit f637149

Please sign in to comment.