Skip to content

Commit d0c0997

Browse files
committed
feat: update CreateEditSkeleton component to accept resource prop and enhance Skeleton loading states
1 parent 63666c4 commit d0c0997

3 files changed

Lines changed: 73 additions & 34 deletions

File tree

adminforth/spa/src/afcl/Skeleton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div
1818
v-else-if="type === 'input'"
1919
role="input"
20-
:class="['animate-pulse bg-gray-100 dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded', $attrs.class]"
20+
:class="['animate-pulse bg-gray-100 dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-default', $attrs.class]"
2121
></div>
2222
<div v-else role="status" class="flex items-center justify-center animate-pulse bg-lightSkeletonIconColor rounded-full dark:bg-darkSkeletonBackgroundColor">
2323
<span class="sr-only">Loading...</span>

adminforth/spa/src/views/CreateEditSkeleton.vue

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,96 @@
1111
</div>
1212
</div>
1313

14-
<div v-for="i in 5" :key="i"
15-
class="flex items-center bg-lightForm dark:bg-darkForm border-b border-gray-100 dark:border-darkFormBorder"
16-
:style="{ height: i === 2 ? '95px' : '75px' }"
17-
>
18-
<div class="w-[208px] flex-shrink-0 px-6 flex items-center gap-1">
14+
<template v-for="column in visibleColumns" :key="column.name">
15+
<div
16+
v-if="isMarkdownEditor(column)"
17+
class="flex items-start bg-lightForm dark:bg-darkForm border-b border-gray-100 dark:border-darkFormBorder"
18+
>
19+
<div class="w-[208px] flex-shrink-0 px-6 pt-7">
1920
<Skeleton class="w-24 h-[10px]" />
2021
</div>
21-
22-
<div class="flex-1 px-6">
23-
<div v-if="i === 2">
24-
<Skeleton type="input" class="h-[42px] w-[160px]" />
25-
<Skeleton class="mt-1 h-[12px] w-20" />
26-
</div>
27-
<Skeleton type="input" v-else-if="i === 4 || i === 5" class="h-[42px] w-[160px]" />
28-
<Skeleton v-else type="input" class="h-[42px] w-full" />
22+
23+
<div class="flex-1 px-6 pt-4 flex flex-col pb-6">
24+
<div class="flex flex-wrap items-center gap-3 p-1.5 border border-gray-300 dark:border-gray-600 rounded-t-lg bg-gray-50 dark:bg-gray-800 w-full h-[46px]">
25+
<template v-for="btn in skeletonButtons" :key="btn.id">
26+
<div class="animate-pulse flex items-center justify-center h-8 px-1 text-gray-300 dark:text-gray-600">
27+
<component :is="btn.icon" class="w-5 h-5" />
28+
</div>
29+
<div v-if="btn.sep" class="w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1"></div>
30+
</template>
2931
</div>
30-
</div>
3132

32-
<div class="flex items-start bg-lightForm dark:bg-darkForm" style="height: 759px;">
33-
<div class="w-[208px] flex-shrink-0 px-6 pt-7">
34-
<Skeleton class="w-24 h-[10px]" />
33+
<div class="animate-pulse bg-white dark:bg-gray-950 border-x border-b border-gray-200 dark:border-gray-700 rounded-b-lg w-full h-[670px]"></div>
34+
</div>
3535
</div>
36-
37-
<div class="flex-1 px-6 pt-4 h-full flex flex-col">
38-
<div class="flex flex-wrap items-center gap-3 p-1.5 border border-gray-300 dark:border-gray-600 rounded-t-lg bg-gray-50 dark:bg-gray-800 w-full box-border h-[44px]">
39-
<template v-for="btn in skeletonButtons" :key="btn.id">
40-
<div class=" animate-pulse flex items-center justify-center h-8 px-1 text-gray-300 dark:text-gray-600">
41-
<component :is="btn.icon" class="w-5 h-5" />
42-
</div>
43-
<div v-if="btn.sep" class="w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1"></div>
44-
</template>
36+
37+
<div
38+
v-else
39+
class="flex items-center bg-lightForm dark:bg-darkForm border-b border-gray-100 dark:border-darkFormBorder"
40+
:style="{ height: getFieldHeight(column) }"
41+
>
42+
<div class="w-[208px] flex-shrink-0 px-6 flex items-center">
43+
<Skeleton class="w-24 h-[10px]" />
44+
</div>
45+
46+
<div class="flex-1 px-6">
47+
<Skeleton type="input" :class="getSkeletonInputClass(column)" />
48+
49+
<div v-if="hasEditingNote(column)" class="mt-1">
50+
<Skeleton class="h-[12px] w-20" />
51+
</div>
4552
</div>
46-
<div class="flex-1 animate-pulse bg-white dark:bg-gray-950 border-x border-b border-gray-200 dark:border-gray-700 rounded-b-lg w-full shadow-inner"></div>
47-
<div class="h-10"></div>
4853
</div>
49-
</div>
54+
55+
</template>
5056
</div>
5157
</div>
5258
</template>
5359

5460
<script setup lang="ts">
55-
import { markRaw } from 'vue';
56-
import { IconExclamationCircleSolid } from '@iconify-prerendered/vue-flowbite';
57-
import {
61+
import { computed, markRaw } from 'vue';
62+
import {
5863
IconLinkOutline, IconCodeOutline, IconRectangleListOutline,
5964
IconOrderedListOutline, IconLetterBoldOutline, IconLetterUnderlineOutline,
6065
IconLetterItalicOutline, IconTextSlashOutline
6166
} from '@iconify-prerendered/vue-flowbite';
6267
import { IconH116Solid, IconH216Solid, IconH316Solid } from '@iconify-prerendered/vue-heroicons';
6368
import { Skeleton } from '@/afcl';
6469
70+
interface Props {
71+
resource?: any;
72+
page?: string;}
73+
74+
const props = withDefaults(defineProps<Props>(), {
75+
page: 'edit'
76+
});
77+
78+
const visibleColumns = computed(() => {
79+
if (!props.resource?.columns) return [];
80+
81+
return props.resource.columns.filter((col: any) => {
82+
if (col.virtual) return false;
83+
if (col.primaryKey) return false;
84+
if (col.backendOnly) return false;
85+
if (col.showIn?.[props.page] === false) return false;
86+
return true;
87+
});
88+
});
89+
90+
const isMarkdownEditor = (column: any) => column.name === 'description';
91+
92+
const hasEditingNote = (column: any) => !!column.editingNote;
93+
94+
const getFieldHeight = (column: any) =>
95+
hasEditingNote(column) ? '95px' : '75px';
96+
97+
const getSkeletonInputClass = (column: any) => {
98+
if (['integer', 'decimal', 'float'].includes(column.type)) {
99+
return 'h-[42px] w-[160px]';
100+
}
101+
return 'h-[42px] w-full';
102+
};
103+
65104
const skeletonButtons = [
66105
{ id: 'bold', icon: markRaw(IconLetterBoldOutline), sep: false },
67106
{ id: 'italic', icon: markRaw(IconLetterItalicOutline), sep: false },

adminforth/spa/src/views/EditView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
:adminUser="coreStore.adminUser"
4242
/>
4343

44-
<CreateEditSkeleton v-if="loading"></CreateEditSkeleton>
44+
<CreateEditSkeleton :resource="coreStore.resource" v-if="loading"></CreateEditSkeleton>
4545

4646
<ResourceForm
4747
v-else-if="coreStore.resource"

0 commit comments

Comments
 (0)