Refactor alerts to TypeScript, remove react-notification dependency (#34239)
This commit is contained in:
parent
e1dbbf6c9d
commit
94d71c992e
14 changed files with 171 additions and 121 deletions
24
app/javascript/mastodon/reducers/alerts.ts
Normal file
24
app/javascript/mastodon/reducers/alerts.ts
Normal 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 [];
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue