Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance list request modifications to fix settings persistence #1556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading