add delete to admin panel
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { type ActionReturnType, actions } from 'astro:actions';
|
||||
import { writable } from 'svelte/store';
|
||||
import { actionErrorPopup } from '@util/action.ts';
|
||||
import { addToWritableArray, deleteFromWritableArray, updateWritableArray } from '@util/state.ts';
|
||||
|
||||
// types
|
||||
export type BlockedUsers = Exclude<ActionReturnType<typeof actions.user.blocked>['data'], undefined>['blocked'];
|
||||
@@ -27,10 +28,7 @@ export async function addBlockedUser(blockedUser: BlockedUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
blockedUsers.update((old) => {
|
||||
old.push(Object.assign(blockedUser, { id: data.id }));
|
||||
return old;
|
||||
});
|
||||
addToWritableArray(blockedUsers, Object.assign(blockedUser, { id: data.id }));
|
||||
}
|
||||
|
||||
export async function editBlockedUser(blockedUser: BlockedUser) {
|
||||
@@ -40,9 +38,15 @@ export async function editBlockedUser(blockedUser: BlockedUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
blockedUsers.update((old) => {
|
||||
const index = old.findIndex((a) => a.id == blockedUser.id);
|
||||
old[index] = blockedUser;
|
||||
return old;
|
||||
});
|
||||
updateWritableArray(blockedUsers, blockedUser, (t) => t.id == blockedUser.id);
|
||||
}
|
||||
|
||||
export async function deleteBlockedUser(blockedUser: BlockedUser) {
|
||||
const { error } = await actions.user.deleteBlocked(blockedUser);
|
||||
if (error) {
|
||||
actionErrorPopup(error);
|
||||
return;
|
||||
}
|
||||
|
||||
deleteFromWritableArray(blockedUsers, (t) => t.id == blockedUser.id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user