Archived
initial redux set up
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
|
||||
import type { RootState, AppDispatch } from "./store";
|
||||
|
||||
// Use throughout your app instead of plain `useDispatch` and `useSelector`
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>();
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
||||
@@ -0,0 +1,55 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
|
||||
interface FavoritesState {
|
||||
favorites: string[];
|
||||
}
|
||||
|
||||
const initialState: FavoritesState = {
|
||||
favorites: [],
|
||||
};
|
||||
|
||||
export const favoritesSlice = createSlice({
|
||||
name: "favorites",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder
|
||||
.addCase(fetchFavorites.fulfilled, (state, action) => {
|
||||
state.favorites = action.payload;
|
||||
})
|
||||
.addCase(addFavorite.fulfilled, (state, action) => {
|
||||
state.favorites.push(action.payload);
|
||||
})
|
||||
.addCase(removeFavorite.fulfilled, (state, action) => {
|
||||
const index = state.favorites.indexOf(action.payload);
|
||||
state.favorites.splice(index, 1);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchFavorites = createAsyncThunk(
|
||||
"favorites/fetchFavorites",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
return ["2", "4"];
|
||||
}
|
||||
);
|
||||
export const addFavorite = createAsyncThunk(
|
||||
"favorites/addFavorite",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
return uuid;
|
||||
}
|
||||
);
|
||||
export const removeFavorite = createAsyncThunk(
|
||||
"favorites/removeFavorite",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
return uuid;
|
||||
}
|
||||
);
|
||||
export const selectFavorites = (state: RootState) => state.favorites.favorites;
|
||||
export default favoritesSlice.reducer;
|
||||
@@ -1,28 +1,33 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import DetailedMeeting from "../../api-bodies/DetailedMeeting";
|
||||
import { RootState } from "../store";
|
||||
|
||||
interface MeetingDetailsOpenState {
|
||||
open: boolean;
|
||||
meeting: DetailedMeeting | null;
|
||||
}
|
||||
|
||||
const initialState: MeetingDetailsOpenState = {
|
||||
open: false,
|
||||
meeting: null,
|
||||
};
|
||||
|
||||
export const meetingDetailsOpenSlice = createSlice({
|
||||
name: "meetingDetailsOpen",
|
||||
initialState,
|
||||
reducers: {
|
||||
open: (state) => {
|
||||
open: (state, action) => {
|
||||
state.open = true;
|
||||
state.meeting = action.payload;
|
||||
},
|
||||
close: (state) => {
|
||||
state.open = false;
|
||||
state.meeting = null;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { open, close } = meetingDetailsOpenSlice.actions;
|
||||
export const selectMeetingDetailsOpen = (state: RootState) =>
|
||||
state.meetingDetailsOpen.open;
|
||||
state.meetingDetailsOpen;
|
||||
export default meetingDetailsOpenSlice.reducer;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import DetailedMeeting from "../../api-bodies/DetailedMeeting";
|
||||
import { RootState } from "../store";
|
||||
import { meetings } from "../../api-bodies/MockData";
|
||||
|
||||
interface MeetingsState {
|
||||
meetings: DetailedMeeting[];
|
||||
}
|
||||
|
||||
const initialState: MeetingsState = {
|
||||
meetings: [],
|
||||
};
|
||||
|
||||
export const meetingsSlice = createSlice({
|
||||
name: "meetings",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(fetchMeetings.fulfilled, (state, action) => {
|
||||
return action.payload;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchMeetings = createAsyncThunk(
|
||||
"meetings/fetchMeetings",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
return { meetings: meetings };
|
||||
}
|
||||
);
|
||||
|
||||
export const selectMeetings = (state: RootState) => state.meetings.meetings;
|
||||
export const selectUserUpcomingMeetings = (state: RootState, uuid: string) => {
|
||||
return state.meetings.meetings.filter((meeting) =>
|
||||
meeting.registrantIds.includes(uuid)
|
||||
);
|
||||
};
|
||||
export default meetingsSlice.reducer;
|
||||
@@ -0,0 +1,40 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import UserLite from "../../api-bodies/UserLite";
|
||||
import { RootState } from "../store";
|
||||
import { people } from "../../api-bodies/MockData";
|
||||
|
||||
interface PeopleState {
|
||||
people: UserLite[];
|
||||
}
|
||||
|
||||
const initialState: PeopleState = {
|
||||
people: [],
|
||||
};
|
||||
|
||||
export const peopleSlice = createSlice({
|
||||
name: "people",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(fetchPeople.fulfilled, (state, action) => {
|
||||
console.log(action.payload);
|
||||
state.people = action.payload;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchPeople = createAsyncThunk(
|
||||
"people/fetchPeople",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
return people;
|
||||
}
|
||||
);
|
||||
|
||||
export const selectFavoritesJSON = (state: RootState, favorites: string[]) => {
|
||||
return state.people.people.filter((p) => favorites.includes(p.uuid));
|
||||
};
|
||||
export const selectTeamJSON = (state: RootState) => state.people.people;
|
||||
export default peopleSlice.reducer;
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
import { team } from "../../api-bodies/MockData";
|
||||
|
||||
interface TeamState {
|
||||
user: string | null;
|
||||
manager: string | null;
|
||||
sameManager: string[];
|
||||
directReports: string[];
|
||||
}
|
||||
|
||||
const initialState: TeamState = {
|
||||
user: null,
|
||||
manager: null,
|
||||
sameManager: [],
|
||||
directReports: [],
|
||||
};
|
||||
|
||||
export const teamSlice = createSlice({
|
||||
name: "team",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(fetchTeam.fulfilled, (state, action) => {
|
||||
return action.payload;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchTeam = createAsyncThunk(
|
||||
"team/fetchTeam",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
return team;
|
||||
}
|
||||
);
|
||||
|
||||
export const selectTeam = (state: RootState) => state.team;
|
||||
export default teamSlice.reducer;
|
||||
@@ -1,9 +1,17 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import meetingDetailsOpenReducer from "./slices/meetingDetailsOpenSlice";
|
||||
import favoritesReducer from "./slices/favoritesSlice";
|
||||
import teamReducer from "./slices/teamSlice";
|
||||
import meetingsReducer from "./slices/meetingsSlice";
|
||||
import peopleReducer from "./slices/peopleSlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
meetingDetailsOpen: meetingDetailsOpenReducer,
|
||||
favorites: favoritesReducer,
|
||||
team: teamReducer,
|
||||
meetings: meetingsReducer,
|
||||
people: peopleReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user