Eugen Rochko b67fc9c099 [Glitch] Refactor alerts to TypeScript, remove react-notification dependency
Port 94d71c992e0fd88fc3a3fc92b598f139c874ab3f to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2025-03-25 21:23:24 +01:00

29 lines
647 B
TypeScript

import { createReducer } from '@reduxjs/toolkit';
import {
showAlert,
dismissAlert,
clearAlerts,
} from 'flavours/glitch/actions/alerts';
import type { Alert } from 'flavours/glitch/models/alert';
const initialState: Alert[] = [];
let id = 0;
export const alertsReducer = createReducer(initialState, (builder) => {
builder
.addCase(showAlert, (state, { payload }) => {
state.push({
key: id++,
...payload,
});
})
.addCase(dismissAlert, (state, { payload: { key } }) => {
return state.filter((item) => item.key !== key);
})
.addCase(clearAlerts, () => {
return [];
});
});