@@ -105,7 +105,7 @@ const props = defineProps<{
105
105
106
106
107
107
const user = ref (usePage ().props .auth .user )
108
- const isPopoverOpen = ref (false )
108
+ const isLoading = ref (false )
109
109
const comment = ref (' ' )
110
110
const loadingState = ref (false )
111
111
const isSetData = ref (false )
@@ -120,18 +120,19 @@ const compCurrentHash = computed(() => {
120
120
121
121
// When click 'Publish'
122
122
const sendDataToServer = async () => {
123
+ isLoading .value = true
123
124
const formValues = {
124
125
... deleteUser (),
125
126
... (props .banner .state !== ' unpublished' && { comment: comment .value }),
126
127
published_hash: compCurrentHash .value // include Hash to save to server
127
128
}
128
-
129
129
const form = useForm (formValues )
130
+
130
131
form .patch (
131
132
route (props .publishRoute [' name' ], props .publishRoute [' parameters' ]), {
132
133
onSuccess : async (res ) => {
133
134
await set (getDbRef (dbPath ), { published_hash: compCurrentHash .value })
134
- // isPopoverOpen .value = false
135
+ isLoading .value = false
135
136
router .visit (route (routeExit [' route' ][' name' ], routeExit [' route' ][' parameters' ]))
136
137
notify ({
137
138
title: " success Update" ,
@@ -240,10 +241,10 @@ const autoSave = () => {
240
241
watch (data , updateData , { deep: true })
241
242
242
243
243
- const validationState= ()=> {
244
- if (props .banner .state !== ' live' ) sendDataToServer ()
245
- else isPopoverOpen .value = true
246
- }
244
+ // const validationState=()=>{
245
+ // if(props.banner.state !== 'live') sendDataToServer()
246
+ // else isPopoverOpen.value = true
247
+ // }
247
248
248
249
const intervalAutoSave = ref (null )
249
250
@@ -269,17 +270,31 @@ const stopInterval=()=>{
269
270
<PageHeading :data =" pageHead" >
270
271
<template #other =" { dataPageHead: head } " >
271
272
<div class =" flex items-center gap-2 relative" >
272
- <Popover >
273
- <template #button >
274
- <!-- 'fd186208ae9dab06d40e49141f34bef9' is Hash from empty data -->
275
- <Button label =" Publish" :style =" compCurrentHash == 'fd186208ae9dab06d40e49141f34bef9' ? 'disabled' : compCurrentHash == data.published_hash ? 'disabled' : 'primary'" :key =" compCurrentHash" :icon =" ['far', 'rocket-launch']" @click =" validationState()"
276
- class =" " >
277
- </Button >
278
- </template >
279
273
280
- <template v-if =" banner .state == ' unpublished' " #popup >
281
- <div ></div >
282
- <!-- Call template to replace the Popover (so the popup isn't appear) -->
274
+ <!-- 'fd186208ae9dab06d40e49141f34bef9' is Hash from empty data -->
275
+ <Button v-if =" banner.state == 'unpublished'"
276
+ label =" Publish"
277
+ :style =" compCurrentHash == 'fd186208ae9dab06d40e49141f34bef9' ? 'disabled' : compCurrentHash == data.published_hash ? 'disabled' : 'primary'"
278
+ :key =" compCurrentHash"
279
+ icon =" far fa-rocket-launch"
280
+ @click =" sendDataToServer()"
281
+ />
282
+
283
+ <!-- If banner already Live, then appear Popover 'comment' before publish -->
284
+ <Popover v-else >
285
+ <template #button =" { isOpen } " >
286
+ <Button v-if =" !isOpen" label =" Publish"
287
+ :style =" compCurrentHash == 'fd186208ae9dab06d40e49141f34bef9'
288
+ ? 'disabled'
289
+ : compCurrentHash == data.published_hash
290
+ ? 'disabled'
291
+ : isOpen
292
+ ? 'cancel'
293
+ : 'primary'"
294
+ :key =" compCurrentHash"
295
+ icon =" far fa-rocket-launch"
296
+ />
297
+ <Button v-else :style =" `cancel`" icon =" fal fa-times" label =" Cancel" />
283
298
</template >
284
299
285
300
<!-- Popover: if already live, add comment to publish it again -->
@@ -294,7 +309,12 @@ const stopInterval=()=>{
294
309
class =" block rounded-md shadow-sm dark:bg-gray-600 dark:text-gray-400 border-gray-300 dark:border-gray-500 focus:border-gray-500 focus:ring-gray-500 sm:text-sm" />
295
310
</div >
296
311
<div class =" flex justify-end" >
297
- <Button size =" xs" @click =" sendDataToServer" icon =" far fa-rocket-launch" label =" Publish" :key =" comment.length" :style =" comment.length ? 'primary' : 'disabled'" />
312
+ <Button size =" xs" @click =" sendDataToServer" icon =" far fa-rocket-launch" label =" Publish" :key =" comment.length" :style =" comment.length ? 'primary' : 'disabled'" >
313
+ <template #icon >
314
+ <FontAwesomeIcon v-if =" isLoading" icon =' fad fa-spinner-third' class =' animate-spin' aria-hidden =' true' />
315
+ <FontAwesomeIcon v-else icon =' far fa-rocket-launch' class =' ' aria-hidden =' true' />
316
+ </template >
317
+ </Button >
298
318
</div >
299
319
</div >
300
320
</template >
0 commit comments