Skip to content

Commit

Permalink
Merge pull request #1556 from clpetersonucf/issue/1553-fix-widget-set…
Browse files Browse the repository at this point in the history
…tings-local-instance-cache

Instance list request modifications to fix settings persistence
  • Loading branch information
clpetersonucf authored Jan 10, 2024
2 parents f38dd85 + c7b5d7a commit 699e343
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fuel/app/classes/materia/widget/instance/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function get_paginated_for_user($user_id, $page_number = 0)
$displayable_inst = array_slice($displayable_inst, $offset, $widgets_per_page);

$data = [
'pagination' => $displayable_inst,
'pagination' => $displayable_inst
];

if ($has_next_page) $data['next_page'] = $page_number + 1;
Expand Down
6 changes: 4 additions & 2 deletions src/components/hooks/useCopyWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default function useCopyWidget() {
pages: previous.pages.map((page, index) => {
if (index == 0) return { ...page, pagination: [ newInst, ...page.pagination] }
else return page
})
}),
modified: Math.floor(Date.now() / 1000)
}))

return { previousValue }
Expand All @@ -51,7 +52,8 @@ export default function useCopyWidget() {
return inst
}) }
else return page
})
}),
modified: Math.floor(Date.now() / 1000)
}))
variables.successFunc(data)
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/hooks/useDeleteWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function useDeleteWidget() {
pages: previous.pages.map((page) => ({
...page,
pagination: page.pagination.filter(widget => widget.id !== inst.instId)
}))
})),
modified: Math.floor(Date.now() / 1000)
}
})

Expand Down
17 changes: 11 additions & 6 deletions src/components/hooks/useUpdateWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,32 @@ export default function useUpdateWidget() {
widgetList = queryClient.getQueryData('widgets')

// widgetList is passed to onSuccess or onError depending on resolution of mutation function
return { widgetList }
return { ...widgetList }
},
onSuccess: (updatedInst, variables) => {

// update successful - insert new values into our local copy of widgetList
for (const page of widgetList?.pages) {
for (const inst of page?.pagination) {
if (inst.id === variables.args[0]) {
inst.open_at = `${variables.args[4]}`
inst.close_at = `${variables.args[5]}`
inst.attempts = `${variables.args[6]}`
inst.open_at = parseInt(variables.args[4])
inst.close_at = parseInt(variables.args[5])
inst.attempts = parseInt(variables.args[6])
inst.guest_access = variables.args[7]
inst.embedded_only = variables.args[8]
break
}
}
}


// update query cache for widgets. This does NOT invalidate the cache, forcing a re-fetch!!
queryClient.setQueryData('widgets', widgetList)
queryClient.setQueryData('widgets', previous => {
return {
...widgetList,
modified: Math.floor(Date.now() / 1000)
}
})

queryClient.invalidateQueries(['user-perms', variables.args[0]])

variables.successFunc(updatedInst)
Expand Down

0 comments on commit 699e343

Please sign in to comment.