only update on changes

This commit is contained in:
Gauthier Roebroeck 2025-12-08 10:22:51 +08:00
parent 12fd9d0424
commit 37d1fca1ad

View file

@ -114,6 +114,16 @@ const localUnpinned = ref<components['schemas']['LibraryDto'][]>([])
void refresh().then(() => {
localPinned.value = pinned.value
localUnpinned.value = unpinned.value
// start watching after initial values are set
watch([localPinned, localUnpinned], ([newPinned, newUnpinned]) => {
const newSettings: Record<string, ClientSettingUserLibrary> = {}
newPinned.forEach((it, index) => (newSettings[it.id] = { order: index, unpinned: false }))
newUnpinned.forEach(
(it, index) => (newSettings[it.id] = { order: newPinned.length + index, unpinned: true }),
)
mutate({ [CLIENT_SETTING_USER.NEXTUI_LIBRARIES]: { value: JSON.stringify(newSettings) } })
})
})
const draggableConfig = {
@ -125,15 +135,6 @@ const draggableConfig = {
}
const { mutate } = useUpdateClientSettingsUser()
watch([localPinned, localUnpinned], ([newPinned, newUnpinned]) => {
const newSettings: Record<string, ClientSettingUserLibrary> = {}
newPinned.forEach((it, index) => (newSettings[it.id] = { order: index, unpinned: false }))
newUnpinned.forEach(
(it, index) => (newSettings[it.id] = { order: newPinned.length + index, unpinned: true }),
)
mutate({ [CLIENT_SETTING_USER.NEXTUI_LIBRARIES]: { value: JSON.stringify(newSettings) } })
})
</script>
<style lang="scss">