layout.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { createSlice, PayloadAction } from "@reduxjs/toolkit";
  2. import type { RootState } from "../store";
  3. export interface IAuthor {
  4. name: string;
  5. email: string;
  6. }
  7. export interface ISite {
  8. logo: string;
  9. title: string;
  10. subhead: string;
  11. keywords: string[];
  12. description: string;
  13. copyright: string;
  14. author: IAuthor;
  15. }
  16. interface IState {
  17. site?: ISite;
  18. title?: string;
  19. }
  20. const initialState: IState = {};
  21. export const slice = createSlice({
  22. name: "layout",
  23. initialState,
  24. reducers: {
  25. refresh: (state, action: PayloadAction<ISite>) => {
  26. state.site = action.payload;
  27. },
  28. setTitle: (state, action: PayloadAction<string>) => {
  29. state.title = action.payload;
  30. },
  31. },
  32. });
  33. export const { refresh, setTitle } = slice.actions;
  34. export const layout = (state: RootState): IState => state.layout;
  35. export const siteInfo = (state: RootState): ISite | undefined =>
  36. state.layout.site;
  37. export const pageTitle = (state: RootState): string | undefined =>
  38. state.layout.title;
  39. export default slice.reducer;