mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-23 00:33:46 +02:00
Switch to a context store for server stuff to better support things in the future
This commit is contained in:
28
resources/scripts/state/flashes.ts
Normal file
28
resources/scripts/state/flashes.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Action, action } from 'easy-peasy';
|
||||
import { FlashMessageType } from '@/components/MessageBox';
|
||||
|
||||
export interface FlashStore {
|
||||
items: FlashMessage[];
|
||||
addFlash: Action<FlashStore, FlashMessage>;
|
||||
clearFlashes: Action<FlashStore, string | void>;
|
||||
}
|
||||
|
||||
export interface FlashMessage {
|
||||
id?: string;
|
||||
key?: string;
|
||||
type: FlashMessageType;
|
||||
title?: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
const flashes: FlashStore = {
|
||||
items: [],
|
||||
addFlash: action((state, payload) => {
|
||||
state.items.push(payload);
|
||||
}),
|
||||
clearFlashes: action((state, payload) => {
|
||||
state.items = payload ? state.items.filter(flashes => flashes.key !== payload) : [];
|
||||
}),
|
||||
};
|
||||
|
||||
export default flashes;
|
||||
Reference in New Issue
Block a user