Switch to a context store for server stuff to better support things in the future
This commit is contained in:
parent
16e6f3f45f
commit
986285402f
21 changed files with 218 additions and 148 deletions
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 a new issue