mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 00:55:50 +00:00
Add navigation preference methods to auth store
- Add updateMe() API method for PATCH requests to /me/ - Add getNavOrder() to retrieve saved navigation order - Add setNavOrder() to persist navigation order changes - Add updateUserPreferences() with optimistic updates and rollback Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0e34415493
commit
e876d6e926
2 changed files with 51 additions and 0 deletions
|
|
@ -2899,6 +2899,19 @@ export default class API {
|
|||
return await request(`${host}/api/accounts/users/me/`);
|
||||
}
|
||||
|
||||
static async updateMe(data) {
|
||||
try {
|
||||
const response = await request(`${host}/api/accounts/users/me/`, {
|
||||
method: 'PATCH',
|
||||
body: data,
|
||||
});
|
||||
return response;
|
||||
} catch (e) {
|
||||
errorNotification('Failed to update user preferences', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
static async getUsers() {
|
||||
try {
|
||||
const response = await request(`${host}/api/accounts/users/`);
|
||||
|
|
|
|||
|
|
@ -30,12 +30,50 @@ const useAuthStore = create((set, get) => ({
|
|||
username: '',
|
||||
email: '',
|
||||
user_level: '',
|
||||
custom_properties: {},
|
||||
},
|
||||
isLoading: false,
|
||||
error: null,
|
||||
|
||||
setUser: (user) => set({ user }),
|
||||
|
||||
updateUserPreferences: async (preferences) => {
|
||||
const currentUser = get().user;
|
||||
const updatedCustomProperties = {
|
||||
...currentUser.custom_properties,
|
||||
...preferences,
|
||||
};
|
||||
|
||||
// Optimistic update
|
||||
set({
|
||||
user: {
|
||||
...currentUser,
|
||||
custom_properties: updatedCustomProperties,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await API.updateMe({
|
||||
custom_properties: updatedCustomProperties,
|
||||
});
|
||||
set({ user: response });
|
||||
return response;
|
||||
} catch (error) {
|
||||
// Revert on failure
|
||||
set({ user: currentUser });
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getNavOrder: () => {
|
||||
const user = get().user;
|
||||
return user?.custom_properties?.navOrder || null;
|
||||
},
|
||||
|
||||
setNavOrder: async (navOrder) => {
|
||||
return await get().updateUserPreferences({ navOrder });
|
||||
},
|
||||
|
||||
initData: async () => {
|
||||
// Prevent multiple simultaneous initData calls
|
||||
if (get().isInitializing || get().isInitialized) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue