notCharles 61da930909 wip
2025-04-24 19:03:34 -04:00

2 lines
859 B
JavaScript

function o({name:r,recordKey:s,state:n}){return{error:void 0,isLoading:!1,state:n,init:function(){Livewire.hook("commit",({component:e,commit:i,succeed:a,fail:u,respond:f})=>{a(({snapshot:h,effect:d})=>{this.$nextTick(()=>{if(this.isLoading||e.id!==this.$root.closest("[wire\\:id]").attributes["wire:id"].value)return;let t=this.getServerState();t===void 0||Alpine.raw(this.state)===t||(this.state=t)})})}),this.$watch("state",async()=>{let e=this.getServerState();if(e===void 0||Alpine.raw(this.state)===e)return;this.isLoading=!0;let i=await this.$wire.updateTableColumnState(r,s,this.state);this.error=i?.error??void 0,!this.error&&this.$refs.serverState&&(this.$refs.serverState.value=this.state?"1":"0"),this.isLoading=!1})},getServerState:function(){if(this.$refs.serverState)return[1,"1"].includes(this.$refs.serverState.value)}}}export{o as default};