Refactor alerts to TypeScript, remove react-notification dependency (#34239)

This commit is contained in:
Eugen Rochko 2025-03-25 19:25:07 +01:00 committed by GitHub
commit 94d71c992e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 171 additions and 121 deletions

View file

@ -0,0 +1,24 @@
import { createReducer } from '@reduxjs/toolkit';
import { showAlert, dismissAlert, clearAlerts } from 'mastodon/actions/alerts';
import type { Alert } from 'mastodon/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 [];
});
});