1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

feat: remembers the sort and direction for containers table on homepage (#2357)

This commit is contained in:
Amir Raminfar
2023-08-20 15:24:04 -07:00
committed by GitHub
parent 26d2f71102
commit 0cd8b3d900
2 changed files with 7 additions and 5 deletions

View File

@@ -91,8 +91,9 @@ const { containers, perPage = 15 } = defineProps<{
containers: Container[];
perPage?: number;
}>();
const sortField: Ref<keyof typeof fields> = ref("created");
const direction = ref<1 | -1>(-1);
type keys = keyof typeof fields;
const sortField = useStorage<keys>("DOZZLE_TABLE_CONTAINERS_SORT", "created");
const direction = useStorage<1 | -1>("DOZZLE_TABLE_CONTAINERS_DIRECTION", -1);
const sortedContainers = computedWithControl(
() => [containers.length, sortField.value, direction.value],
() => {
@@ -112,7 +113,7 @@ const paginated = computed(() => {
return sortedContainers.value.slice(start, end);
});
function sort(field: keyof typeof fields) {
function sort(field: keys) {
if (sortField.value === field) {
direction.value *= -1;
} else {
@@ -120,7 +121,7 @@ function sort(field: keyof typeof fields) {
direction.value = 1;
}
}
function isVisible(field: keyof typeof fields) {
function isVisible(field: keys) {
return fields[field].mobileVisible || !isMobile.value;
}
</script>