22 lines
685 B
TypeScript
22 lines
685 B
TypeScript
import { type ActionReturnType, actions } from 'astro:actions';
|
|
import { writable } from 'svelte/store';
|
|
import { actionErrorPopup } from '@util/action.ts';
|
|
|
|
// types
|
|
export type Feedbacks = Exclude<ActionReturnType<typeof actions.feedback.feedbacks>['data'], undefined>['feedbacks'];
|
|
export type Feedback = Feedbacks[0];
|
|
|
|
// state
|
|
export const feedbacks = writable<Feedbacks>([]);
|
|
|
|
// actions
|
|
export async function fetchFeedbacks(reporter?: string | null, reported?: string | null) {
|
|
const { data, error } = await actions.feedback.feedbacks({ reporter: reporter, reported: reported });
|
|
if (error) {
|
|
actionErrorPopup(error);
|
|
return;
|
|
}
|
|
|
|
feedbacks.set(data.feedbacks);
|
|
}
|