Skip to content

Commit d3c84f8

Browse files
authored
Merge pull request #11 from coder-inbox/search
implement search, rm react logo, optimize images
2 parents e49d755 + 124b856 commit d3c84f8

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

public/banner.png

100755100644
-1.39 MB
Loading

public/features.png

-1.36 MB
Loading

src/assets/react.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/AppHeader/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SettingsIcon from "@mui/icons-material/Settings";
1313
import SearchIcon from "@mui/icons-material/Search";
1414
import RefreshIcon from "@mui/icons-material/Refresh";
1515
import {
16-
setFilterType,
16+
searchEmails,
1717
toggleSidebarCollapsed,
1818
} from "@app/store/mailAppReducer/actions";
1919
import { uploadPicture, userLogout } from "@app/store/authReducer/actions";
@@ -82,7 +82,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
8282
const handleSearchText = (e) => {
8383
setSearchTextState(e.target.value);
8484
dispatch(
85-
setFilterType({
85+
searchEmails({
8686
selectedFolder: !searchTextState && "inbox",
8787
selectedFilter: "",
8888
selectedLabel: "",

src/store/mailAppReducer/actions/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ export const setFilterType = createAsyncThunk(
1717
}
1818
);
1919

20+
export const searchEmails = createAsyncThunk(
21+
"mailbox/searchEmails",
22+
async (filterType, { rejectWithValue }) => {
23+
try {
24+
if (filterType.searchText.length > 0) {
25+
const config = {
26+
headers: {
27+
"Content-Type": "application/json",
28+
Authorization: JSON.parse(localStorage.getItem("token")),
29+
email: JSON.parse(localStorage.getItem("user")).email,
30+
},
31+
params: { search: filterType.searchText },
32+
};
33+
const response = await axios.get(
34+
`${baseURL}/nylas/search-emails`,
35+
config
36+
);
37+
return response.data;
38+
}
39+
} catch (error) {
40+
return rejectWithValue(error.response?.data || "Something went wrong");
41+
}
42+
}
43+
);
44+
2045
export const getLabelsList = createAsyncThunk(
2146
"mailbox/getLabelsList",
2247
async (_, { rejectWithValue }) => {

src/store/mailAppReducer/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
getSelectedMail,
2020
updateSelectedMail,
2121
replyToMail,
22+
searchEmails,
2223
nullifySelectedMail as nullifySelectedMailThunk,
2324
} from "./actions";
2425

@@ -38,6 +39,7 @@ const initialState = {
3839
selectedMail: null,
3940
totalMailCount: null,
4041
loading: {
42+
searchEmails: false,
4143
isSideBarCollapsed: false,
4244
setFilterType: false,
4345
getLabelsList: false,
@@ -61,6 +63,7 @@ const initialState = {
6163
},
6264
error: {
6365
isSideBarCollapsed: null,
66+
searchEmails: null,
6467
setFilterType: null,
6568
getLabelsList: null,
6669
addNewLabel: null,
@@ -597,6 +600,23 @@ const mailAppReducer = createSlice({
597600
state.loading.replyToMail = false;
598601
state.error.replyToMail = action.payload;
599602
});
603+
604+
// Async Thunk: replyToMail
605+
builder
606+
.addCase(searchEmails.pending, (state) => {
607+
state.loading.searchEmails = true;
608+
state.error.searchEmails = null;
609+
})
610+
.addCase(searchEmails.fulfilled, (state, action) => {
611+
state.loading.searchEmails = false;
612+
if (action.payload?.length > 0) {
613+
state.mailsList = action.payload;
614+
}
615+
})
616+
.addCase(searchEmails.rejected, (state, action) => {
617+
state.loading.searchEmails = false;
618+
state.error.searchEmails = "Something went wrong!";
619+
});
600620
},
601621
});
602622

0 commit comments

Comments
 (0)