Archived
redux updates
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
import { favorites } from "../../api-bodies/MockData";
|
||||
|
||||
interface FavoritesState {
|
||||
favorites: string[];
|
||||
@@ -34,7 +35,7 @@ export const fetchFavorites = createAsyncThunk(
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
return ["2", "4"];
|
||||
return favorites;
|
||||
}
|
||||
);
|
||||
export const addFavorite = createAsyncThunk(
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import DetailedMeeting from "../../api-bodies/DetailedMeeting";
|
||||
import { RootState } from "../store";
|
||||
import { meetings } from "../../api-bodies/MockData";
|
||||
import UserStatus from "../../api-bodies/UserStatus";
|
||||
|
||||
interface MeetingsAndUserStatusState {
|
||||
meetings: DetailedMeeting[];
|
||||
userStatuses: Record<string, UserStatus>;
|
||||
}
|
||||
|
||||
const initialState: MeetingsAndUserStatusState = {
|
||||
meetings: [],
|
||||
userStatuses: {},
|
||||
};
|
||||
|
||||
export const meetingsAndUserStatusSlice = createSlice({
|
||||
name: "meetingsAndUserStatus",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(fetchMeetings.fulfilled, (state, action) => {
|
||||
state.meetings = action.payload.meetings;
|
||||
state.userStatuses = action.payload.userStatuses;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchMeetings = createAsyncThunk(
|
||||
"meetingsAndUserStatus/fetchMeetings",
|
||||
async (uuid: string) => {
|
||||
// const response = await client.post("/fakeApi/posts", initialPost);
|
||||
// !!!
|
||||
console.log(uuid);
|
||||
const userStatuses: Record<string, UserStatus> = {};
|
||||
meetings.forEach((meeting) => {
|
||||
meeting.liveParticipantIds.forEach((uuid) => {
|
||||
userStatuses[uuid] = {
|
||||
uuid: uuid,
|
||||
inMeeting: true,
|
||||
meetingID: meeting.meetingId,
|
||||
};
|
||||
});
|
||||
});
|
||||
return { userStatuses: userStatuses, meetings: meetings };
|
||||
}
|
||||
);
|
||||
|
||||
export const selectMeetings = (state: RootState) =>
|
||||
state.meetingsAndUserStatuses.meetings;
|
||||
export const selectMeeting = (state: RootState, meetingID: string | null) => {
|
||||
return meetingID !== null
|
||||
? state.meetingsAndUserStatuses.meetings.find(
|
||||
(meeting) => meeting.meetingId === meetingID
|
||||
)
|
||||
: null;
|
||||
};
|
||||
export const selectUserUpcomingMeetings = (state: RootState, uuid: string) => {
|
||||
return state.meetingsAndUserStatuses.meetings.filter((meeting) =>
|
||||
meeting.registrantIds.includes(uuid)
|
||||
);
|
||||
};
|
||||
export const selectUserStatus = (
|
||||
state: RootState,
|
||||
uuid: string
|
||||
): UserStatus => {
|
||||
const userStatus = state.meetingsAndUserStatuses.userStatuses[uuid];
|
||||
if (userStatus) {
|
||||
return userStatus;
|
||||
} else {
|
||||
return {
|
||||
uuid: uuid,
|
||||
inMeeting: false,
|
||||
meetingID: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
export default meetingsAndUserStatusSlice.reducer;
|
||||
@@ -1,41 +0,0 @@
|
||||
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;
|
||||
@@ -1,40 +0,0 @@
|
||||
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;
|
||||
@@ -1,41 +0,0 @@
|
||||
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;
|
||||
@@ -0,0 +1,66 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
import { userLites, team } from "../../api-bodies/MockData";
|
||||
import UserLite from "../../api-bodies/UserLite";
|
||||
|
||||
interface TeamState {
|
||||
user: string | null;
|
||||
manager: string | null;
|
||||
sameManager: string[];
|
||||
directReports: string[];
|
||||
}
|
||||
|
||||
interface UsersState {
|
||||
users: Record<string, UserLite>;
|
||||
team: TeamState;
|
||||
}
|
||||
|
||||
const initialState: UsersState = {
|
||||
users: {},
|
||||
team: { user: null, manager: null, sameManager: [], directReports: [] },
|
||||
};
|
||||
|
||||
export const usersSlice = createSlice({
|
||||
name: "users",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(fetchUsers.fulfilled, (state, action) => {
|
||||
state.users = action.payload.users;
|
||||
state.team = action.payload.team;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const fetchUsers = createAsyncThunk(
|
||||
"users/fetchUsers",
|
||||
async (uuid: string) => {
|
||||
// fetch userfull
|
||||
// fetch managerfull
|
||||
// now you have yourself, co-workers, manager, and direct reports (your team basically!)
|
||||
// call setTeam reducer in teamSlice
|
||||
console.log(uuid);
|
||||
const users: Record<string, UserLite> = {};
|
||||
userLites.forEach((userLite) => {
|
||||
users[userLite.uuid] = userLite;
|
||||
});
|
||||
return { users: users, team: team };
|
||||
}
|
||||
);
|
||||
|
||||
export const selectUsers = (state: RootState, uuids: string[]): UserLite[] => {
|
||||
const users: UserLite[] = [];
|
||||
uuids.forEach((uuid) => users.push(state.users.users[uuid]));
|
||||
return users;
|
||||
};
|
||||
export const selectTeam = (state: RootState) => {
|
||||
const team: UserLite[] = [];
|
||||
if (state.users.team.manager !== null)
|
||||
team.push(state.users.users[state.users.team.manager]);
|
||||
state.users.team.sameManager.forEach((u) => team.push(state.users.users[u]));
|
||||
state.users.team.directReports.forEach((u) =>
|
||||
team.push(state.users.users[u])
|
||||
);
|
||||
return team;
|
||||
};
|
||||
export default usersSlice.reducer;
|
||||
+4
-6
@@ -1,17 +1,15 @@
|
||||
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";
|
||||
import meetingsAndUserStatusReducer from "./slices/meetingsAndUserStatusSlice";
|
||||
import usersReducer from "./slices/usersSlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
meetingDetailsOpen: meetingDetailsOpenReducer,
|
||||
favorites: favoritesReducer,
|
||||
team: teamReducer,
|
||||
meetings: meetingsReducer,
|
||||
people: peopleReducer,
|
||||
meetingsAndUserStatuses: meetingsAndUserStatusReducer,
|
||||
users: usersReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user