Skip to content

Commit

Permalink
Merge pull request #11 from coder-inbox/search
Browse files Browse the repository at this point in the history
implement search, rm react logo, optimize images
  • Loading branch information
wiseaidev authored Oct 2, 2023
2 parents e49d755 + 124b856 commit d3c84f8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Binary file modified public/banner.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/AppHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SettingsIcon from "@mui/icons-material/Settings";
import SearchIcon from "@mui/icons-material/Search";
import RefreshIcon from "@mui/icons-material/Refresh";
import {
setFilterType,
searchEmails,
toggleSidebarCollapsed,
} from "@app/store/mailAppReducer/actions";
import { uploadPicture, userLogout } from "@app/store/authReducer/actions";
Expand Down Expand Up @@ -82,7 +82,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
const handleSearchText = (e) => {
setSearchTextState(e.target.value);
dispatch(
setFilterType({
searchEmails({
selectedFolder: !searchTextState && "inbox",
selectedFilter: "",
selectedLabel: "",
Expand Down
25 changes: 25 additions & 0 deletions src/store/mailAppReducer/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ export const setFilterType = createAsyncThunk(
}
);

export const searchEmails = createAsyncThunk(
"mailbox/searchEmails",
async (filterType, { rejectWithValue }) => {
try {
if (filterType.searchText.length > 0) {
const config = {
headers: {
"Content-Type": "application/json",
Authorization: JSON.parse(localStorage.getItem("token")),
email: JSON.parse(localStorage.getItem("user")).email,
},
params: { search: filterType.searchText },
};
const response = await axios.get(
`${baseURL}/nylas/search-emails`,
config
);
return response.data;
}
} catch (error) {
return rejectWithValue(error.response?.data || "Something went wrong");
}
}
);

export const getLabelsList = createAsyncThunk(
"mailbox/getLabelsList",
async (_, { rejectWithValue }) => {
Expand Down
20 changes: 20 additions & 0 deletions src/store/mailAppReducer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getSelectedMail,
updateSelectedMail,
replyToMail,
searchEmails,
nullifySelectedMail as nullifySelectedMailThunk,
} from "./actions";

Expand All @@ -38,6 +39,7 @@ const initialState = {
selectedMail: null,
totalMailCount: null,
loading: {
searchEmails: false,
isSideBarCollapsed: false,
setFilterType: false,
getLabelsList: false,
Expand All @@ -61,6 +63,7 @@ const initialState = {
},
error: {
isSideBarCollapsed: null,
searchEmails: null,
setFilterType: null,
getLabelsList: null,
addNewLabel: null,
Expand Down Expand Up @@ -597,6 +600,23 @@ const mailAppReducer = createSlice({
state.loading.replyToMail = false;
state.error.replyToMail = action.payload;
});

// Async Thunk: replyToMail
builder
.addCase(searchEmails.pending, (state) => {
state.loading.searchEmails = true;
state.error.searchEmails = null;
})
.addCase(searchEmails.fulfilled, (state, action) => {
state.loading.searchEmails = false;
if (action.payload?.length > 0) {
state.mailsList = action.payload;
}
})
.addCase(searchEmails.rejected, (state, action) => {
state.loading.searchEmails = false;
state.error.searchEmails = "Something went wrong!";
});
},
});

Expand Down

0 comments on commit d3c84f8

Please sign in to comment.