Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helpful clear flash action for the flash slice #57

Open
jho406 opened this issue May 6, 2024 · 0 comments
Open

Add a helpful clear flash action for the flash slice #57

jho406 opened this issue May 6, 2024 · 0 comments

Comments

@jho406
Copy link
Collaborator

jho406 commented May 6, 2024

The default flash slice generated by superglue is very basic, and I find myself making edits to it soon after.

Mine looks like this:

import { createSlice } from '@reduxjs/toolkit';
import { saveResponse, beforeVisit } from '../actions';

export const flashSlice = createSlice({
  name: 'flash',
  initialState: {},
  reducers: {
    clearFlash() {
      return {};
    },
    flash(state, { payload }) {
      return payload;
    },
  },
  extraReducers: (builder) => {
    builder.addCase(beforeVisit, (state, action) => {
      return {};
    });
    builder.addCase(saveResponse, (state, action) => {
      const { page } = action.payload;

      return {
        ...state,
        ...page.slices.flash,
      };
    });
  },
});

export const { clearFlash, flash } = flashSlice.actions;

It comes with two action creators, one clearFlash to clear the flash away, for example clicking on an X on a flash message, or creating a new one client side using flash. This seems like handy things to have out-of-the-box. Lets take what we have in that snippet and replace the generator's version.

@jho406 jho406 added this to Superglue Jun 24, 2024
@jho406 jho406 moved this to Ready for contributors in Superglue Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
Development

No branches or pull requests

1 participant