Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions adminforth/spa/src/components/ResourceListTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
<SkeleteLoader
v-if="!rows"
:columns="resource?.columns.filter(c => c.showIn.list).length + 2"
:rows="3"
:rows="rowHeights.length || 3"
:row-heights="rowHeights"
/>
<tr v-else-if="rows.length === 0" class="bg-lightListTable dark:bg-darkListTable dark:border-darkListTableBorder">
<td :colspan="resource?.columns.length + 2">
Expand All @@ -80,6 +81,7 @@

<tr @click="onClick($event,row)"
v-else v-for="(row, rowI) in rows" :key="`row_${row._primaryKeyValue}`"
ref="rowRefs"
class="bg-lightListTable dark:bg-darkListTable border-lightListBorder dark:border-gray-700 hover:bg-lightListTableRowHover dark:hover:bg-darkListTableRowHover"

:class="{'border-b': rowI !== rows.length - 1, 'cursor-pointer': row._clickUrl !== null}"
Expand Down Expand Up @@ -269,7 +271,7 @@
<script setup lang="ts">


import { computed, onMounted, ref, watch, type Ref } from 'vue';
import { computed, onMounted, ref, watch, useTemplateRef, type Ref } from 'vue';
import { callAdminForthApi } from '@/utils';
import { useI18n } from 'vue-i18n';
import ValueRenderer from '@/components/ValueRenderer.vue';
Expand Down Expand Up @@ -347,6 +349,13 @@ watch(() => props.page, (newPage) => {
page.value = newPage;
});

const rowRefs = useTemplateRef('rowRefs');
const rowHeights = ref([]);
watch(() => props.rows, (newRows) => {
// rows are set to null when new records are loading
rowHeights.value = newRows ? [] : rowRefs.value.map((el) => el.offsetHeight);
});

function addToCheckedValues(id) {
if (checkboxesInternal.value.includes(id)) {
checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== id);
Expand Down
15 changes: 11 additions & 4 deletions adminforth/spa/src/components/SkeleteLoader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<tr v-for="c in new Array(props.rows)" class="bg-lightListTable border-b dark:bg-darkListTable dark:border-darkListBorder">
<td v-for="r in new Array(props.columns)" class="items-center px-6 py-8 cursor-default" >
<tr
v-for="(r, ri) in new Array(props.rows)"
class="bg-lightListTable border-b dark:bg-darkListTable dark:border-darkListBorder"
:style="[props.rowHeights[ri] !== undefined ? `height: ${props.rowHeights[ri]}px` : '' ]"
>
<td v-for="c in new Array(props.columns)" class="items-center px-6 py-8 cursor-default" >
<div role="status" class="max-w-sm animate-pulse">
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[360px]"></div>
</div>
Expand All @@ -10,9 +14,12 @@

<script setup lang="ts">

const props = defineProps<{
const props = withDefaults(defineProps<{
columns: number;
rows: number;
}>();
rowHeights?: number[];
}>(), {
rowHeights: [],
});

</script>