mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
feat: remembers the sort and direction for containers table on homepage (#2357)
This commit is contained in:
@@ -91,8 +91,9 @@ const { containers, perPage = 15 } = defineProps<{
|
|||||||
containers: Container[];
|
containers: Container[];
|
||||||
perPage?: number;
|
perPage?: number;
|
||||||
}>();
|
}>();
|
||||||
const sortField: Ref<keyof typeof fields> = ref("created");
|
type keys = keyof typeof fields;
|
||||||
const direction = ref<1 | -1>(-1);
|
const sortField = useStorage<keys>("DOZZLE_TABLE_CONTAINERS_SORT", "created");
|
||||||
|
const direction = useStorage<1 | -1>("DOZZLE_TABLE_CONTAINERS_DIRECTION", -1);
|
||||||
const sortedContainers = computedWithControl(
|
const sortedContainers = computedWithControl(
|
||||||
() => [containers.length, sortField.value, direction.value],
|
() => [containers.length, sortField.value, direction.value],
|
||||||
() => {
|
() => {
|
||||||
@@ -112,7 +113,7 @@ const paginated = computed(() => {
|
|||||||
return sortedContainers.value.slice(start, end);
|
return sortedContainers.value.slice(start, end);
|
||||||
});
|
});
|
||||||
|
|
||||||
function sort(field: keyof typeof fields) {
|
function sort(field: keys) {
|
||||||
if (sortField.value === field) {
|
if (sortField.value === field) {
|
||||||
direction.value *= -1;
|
direction.value *= -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -120,7 +121,7 @@ function sort(field: keyof typeof fields) {
|
|||||||
direction.value = 1;
|
direction.value = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function isVisible(field: keyof typeof fields) {
|
function isVisible(field: keys) {
|
||||||
return fields[field].mobileVisible || !isMobile.value;
|
return fields[field].mobileVisible || !isMobile.value;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Container } from "@/models/Container";
|
import { Container } from "@/models/Container";
|
||||||
|
|
||||||
export const sessionHost = useSessionStorage<string | null>("host", null);
|
const DOZZLE_HOST = "DOZZLE_HOST";
|
||||||
|
export const sessionHost = useSessionStorage<string | null>(DOZZLE_HOST, null);
|
||||||
|
|
||||||
if (config.hosts.length === 1 && !sessionHost.value) {
|
if (config.hosts.length === 1 && !sessionHost.value) {
|
||||||
sessionHost.value = config.hosts[0].id;
|
sessionHost.value = config.hosts[0].id;
|
||||||
|
|||||||
Reference in New Issue
Block a user