Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5c628ec

Browse files
cache data added
1 parent d4782b6 commit 5c628ec

File tree

7 files changed

+156
-94
lines changed

7 files changed

+156
-94
lines changed

src/App.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,19 @@ const App = () => {
112112
if (diff) {
113113
store.dispatch(actions.filter.updateGigFilter(updatedGigFilter));
114114
}
115+
if (updatedGigFilter.status !== initialGigFilter.status) {
116+
// preload the open application first page data.
117+
const cachedOpenGigs = store.getState().myGigs[initialGigFilter.status];
118+
if (!cachedOpenGigs.myGigs) {
119+
store.dispatch(
120+
actions.myGigs.getMyOpenGigs(
121+
constants.GIGS_FILTER_STATUSES_PARAM[initialGigFilter.status]
122+
)
123+
);
124+
}
125+
}
115126
const cachedGigs = store.getState().myGigs[updatedGigFilter.status];
116-
if (cachedGigs.myGigs && cachedGigs.myGigs.length !== 0) {
127+
if (cachedGigs.myGigs) {
117128
return;
118129
}
119130
getDataDebounced.current(() => {

src/actions/myGigs.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import service from "../services/myGigs";
1212
* @param {number} perPage items per page. by default is 10.
1313
* @returns
1414
*/
15-
async function getMyGigs(status = "open_jobs", page = 1, perPage = PER_PAGE) {
16-
return service.getMyGigs(status, page, perPage);
17-
}
15+
// async function getMyGigs(status = "open_jobs", page = 1, perPage = PER_PAGE) {
16+
// return service.getMyGigs(status, page, perPage);
17+
// }
1818

1919
async function getMyActiveGigs(
2020
status = "active_jobs",
@@ -54,9 +54,9 @@ async function getMyArchivedGigsDone(
5454
* @param {*} perPage items per page. by default is 10
5555
* @returns
5656
*/
57-
async function loadMoreMyGigs(status, nextPage, perPage = PER_PAGE) {
58-
return service.getMyGigs(status, nextPage, perPage);
59-
}
57+
// async function loadMoreMyGigs(status, nextPage, perPage = PER_PAGE) {
58+
// return service.getMyGigs(status, nextPage, perPage);
59+
// }
6060

6161
async function getProfile() {
6262
return service.getProfile();
@@ -90,8 +90,8 @@ export default createActions({
9090
GET_MY_OPEN_GIGS: getMyOpenGigs,
9191
GET_MY_COMPLETED_GIGS: getMyCompletedGigs,
9292
GET_MY_ARCHIVED_GIGS: getMyArchivedGigsDone,
93-
GET_MY_GIGS: getMyGigs,
94-
LOAD_MORE_MY_GIGS: loadMoreMyGigs,
93+
// GET_MY_GIGS: getMyGigs,
94+
// LOAD_MORE_MY_GIGS: loadMoreMyGigs,
9595
GET_PROFILE: getProfile,
9696
UPDATE_PROFILE: updateProfile,
9797
START_CHECKING_GIGS: startCheckingGigs,

src/constants/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export const SORT_STATUS_ORDER = [
359359
MY_GIG_PHASE.COMPLETED,
360360
];
361361

362-
export const PER_PAGE = 10;
362+
export const PER_PAGE = 1;
363363

364364
/**
365365
* defines which status can show remarks

src/containers/MyGigs/JobListing/JobCard/tooltips/EarnTooltip/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
padding: 7px 10px;
66
line-height: $line-height-base;
77
font-size: 12px;
8+
text-align: center;
89
}

src/containers/MyGigs/JobListing/index.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ import * as constants from "../../../constants";
77

88
import "./styles.scss";
99

10-
const JobListing = ({ jobs, loadMore, total, numLoaded, gigStatus }) => {
10+
const JobListing = ({ jobs, loadMore, total, numLoaded, gigStatus, page }) => {
1111
const scrollLock = useScrollLock();
12-
const [page, setPage] = useState(1);
12+
// const [page, setPage] = useState(1);
1313

1414
const varsRef = useRef();
1515
varsRef.current = { scrollLock };
1616

1717
const handleLoadMoreClick = () => {
1818
const nextPage = page + 1;
1919
scrollLock(true);
20-
setPage(nextPage);
20+
// setPage(nextPage);
2121
loadMore(constants.GIGS_FILTER_STATUSES_PARAM[gigStatus], nextPage);
2222
};
2323

2424
useEffect(() => {
2525
varsRef.current.scrollLock(false);
2626
}, [jobs]);
2727

28-
useEffect(() => {
29-
setPage(1);
30-
}, [gigStatus]);
28+
// useEffect(() => {
29+
// setPage(1);
30+
// }, [gigStatus]);
3131
return (
3232
<div styleName="card-container">
3333
{![
@@ -75,6 +75,7 @@ JobListing.propTypes = {
7575
total: PT.number,
7676
numLoaded: PT.number,
7777
gigStatus: PT.string,
78+
page: PT.number,
7879
};
7980

8081
export default JobListing;

src/containers/MyGigs/index.jsx

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useEffect, useRef, useState } from "react";
2-
import { useLocation } from "@reach/router";
1+
import React, { useEffect, useRef, useState, useCallback } from "react";
2+
// import { useLocation } from "@reach/router";
33
import PT from "prop-types";
44
import { connect } from "react-redux";
55
import Modal from "../../components/Modal";
@@ -17,11 +17,11 @@ import UpdateSuccess from "./modals/UpdateSuccess";
1717
import "./styles.scss";
1818

1919
const MyGigs = ({
20-
myGigs,
21-
getMyGigs,
22-
loadMore,
23-
total,
24-
numLoaded,
20+
// myGigs,
21+
// getMyGigs,
22+
// loadMore,
23+
// total,
24+
// numLoaded,
2525
myActiveGigs,
2626
myOpenGigs,
2727
myCompletedGigs,
@@ -35,12 +35,17 @@ const MyGigs = ({
3535
startCheckingGigs,
3636
gigStatus,
3737
loadingMyGigs,
38+
getMyActiveGigs,
39+
getMyOpenGigs,
40+
getMyCompletedGigs,
41+
getMyArchivedGigs,
3842
}) => {
3943
// const location = useLocation();
4044
// const params = utils.url.parseUrlQuery(location.search);
4145
const propsRef = useRef();
4246
propsRef.current = {
43-
getMyGigs,
47+
// getMyGigs,
48+
getMyOpenGigs,
4449
getProfile,
4550
getAllCountries,
4651
startCheckingGigs,
@@ -59,7 +64,8 @@ const MyGigs = ({
5964
return;
6065
}
6166
if (!checkingGigs) {
62-
propsRef.current.getMyGigs();
67+
// propsRef.current.getMyGigs();
68+
propsRef.current.getMyOpenGigs();
6369
}
6470
}, [checkingGigs]);
6571

@@ -90,6 +96,30 @@ const MyGigs = ({
9096
}
9197
}, [updateProfileSuccess]);
9298

99+
const currentLoadMore = useCallback(
100+
(status, page) => {
101+
if (gigStatus == constants.GIGS_FILTER_STATUSES.ACTIVE_JOBS) {
102+
getMyActiveGigs(status, page);
103+
}
104+
if (gigStatus == constants.GIGS_FILTER_STATUSES.OPEN_JOBS) {
105+
getMyOpenGigs(status, page);
106+
}
107+
if (gigStatus == constants.GIGS_FILTER_STATUSES.COMPLETED_JOBS) {
108+
getMyCompletedGigs(status, page);
109+
}
110+
if (gigStatus == constants.GIGS_FILTER_STATUSES.ARCHIVED_JOBS) {
111+
getMyArchivedGigs(status, page);
112+
}
113+
},
114+
[
115+
gigStatus,
116+
getMyActiveGigs,
117+
getMyOpenGigs,
118+
getMyCompletedGigs,
119+
getMyArchivedGigs,
120+
]
121+
);
122+
93123
return (
94124
<>
95125
<div styleName="page">
@@ -126,12 +156,15 @@ const MyGigs = ({
126156
<JobListing
127157
gigStatus={gigStatus}
128158
jobs={currentGigs.myGigs}
129-
loadMore={loadMore}
159+
loadMore={currentLoadMore}
130160
total={currentGigs.total}
131161
numLoaded={currentGigs.numLoaded}
162+
page={currentGigs.page}
132163
/>
133164
)}
134-
{checkingGigs || (loadingMyGigs && !currentGigs.myGigs && <Loading />)}
165+
{(checkingGigs || (loadingMyGigs && !currentGigs.myGigs)) && (
166+
<Loading />
167+
)}
135168
</div>
136169
<Modal open={openUpdateProfile}>
137170
<UpdateGigProfile
@@ -158,11 +191,11 @@ const MyGigs = ({
158191

159192
MyGigs.propTypes = {
160193
gigStatus: PT.string,
161-
myGigs: PT.arrayOf(PT.shape()),
162-
getMyGigs: PT.func,
163-
loadMore: PT.func,
164-
total: PT.number,
165-
numLoaded: PT.number,
194+
// myGigs: PT.arrayOf(PT.shape()),
195+
// getMyGigs: PT.func,
196+
// loadMore: PT.func,
197+
// total: PT.number,
198+
// numLoaded: PT.number,
166199
profile: PT.shape(),
167200
getProfile: PT.func,
168201
updateProfile: PT.func,
@@ -175,14 +208,18 @@ MyGigs.propTypes = {
175208
myCompletedGigs: PT.shape(),
176209
myArchivedGigs: PT.shape(),
177210
loadingMyGigs: PT.bool,
211+
getMyActiveGigs: PT.func,
212+
getMyOpenGigs: PT.func,
213+
getMyCompletedGigs: PT.func,
214+
getMyArchivedGigs: PT.func,
178215
};
179216

180217
const mapStateToProps = (state) => ({
181218
gigStatus: state.filter.gig.status,
182219
checkingGigs: state.myGigs.checkingGigs,
183-
myGigs: state.myGigs.myGigs,
184-
total: state.myGigs.total,
185-
numLoaded: state.myGigs.numLoaded,
220+
// myGigs: state.myGigs.myGigs,
221+
// total: state.myGigs.total,
222+
// numLoaded: state.myGigs.numLoaded,
186223
loadingMyGigs: state.myGigs.loadingMyGigs,
187224
myActiveGigs: state.myGigs[constants.GIGS_FILTER_STATUSES.ACTIVE_JOBS],
188225
myOpenGigs: state.myGigs[constants.GIGS_FILTER_STATUSES.OPEN_JOBS],
@@ -193,8 +230,12 @@ const mapStateToProps = (state) => ({
193230
});
194231

195232
const mapDispatchToProps = {
196-
getMyGigs: actions.myGigs.getMyGigs,
197-
loadMore: actions.myGigs.loadMoreMyGigs,
233+
// getMyGigs: actions.myGigs.getMyGigs,
234+
// loadMore: actions.myGigs.loadMoreMyGigs,
235+
getMyActiveGigs: actions.myGigs.getMyActiveGigs,
236+
getMyOpenGigs: actions.myGigs.getMyOpenGigs,
237+
getMyCompletedGigs: actions.myGigs.getMyCompletedGigs,
238+
getMyArchivedGigs: actions.myGigs.getMyArchivedGigs,
198239
getProfile: actions.myGigs.getProfile,
199240
updateProfile: actions.myGigs.updateProfile,
200241
getAllCountries: actions.lookup.getAllCountries,

0 commit comments

Comments
 (0)