Skip to content

Commit 95dfe41

Browse files
Merge pull request #105 from GauravWalia19/searchSection
Completed the basic Search section for mobile
2 parents 3d96d2f + e2cecf3 commit 95dfe41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1289
-284
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"devDependencies": {
1717
"@types/react": "^18.2.15",
1818
"@types/react-dom": "^18.2.7",
19-
"@vitejs/plugin-react-swc": "^3.3.2",
19+
"@vitejs/plugin-react-swc": "^3.7.1",
2020
"eslint": "^8.45.0",
2121
"eslint-plugin-react": "^7.32.2",
2222
"eslint-plugin-react-hooks": "^4.6.0",
2323
"eslint-plugin-react-refresh": "^0.4.3",
24-
"vite": "^4.4.5"
24+
"vite": "^5.4.8"
2525
}
2626
}

src/components/App/App.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './App.css';
44
import RatingPopupHandler from '../RatingPopup';
55
import ToastMessagesContainer from '../ToastMessages';
66
import { useAppReducer } from '../hooks/useAppReducer.js';
7+
import SearchSectionContainer from '../SearchSection';
78

89
function App() {
910
const [state, appDispatch] = useAppReducer();
@@ -20,6 +21,7 @@ function App() {
2021
toastMessages={state.toastMessages}
2122
appDispatch={appDispatch}
2223
/>
24+
<SearchSectionContainer accessToken={state.accessToken} />
2325
</>
2426
);
2527
}

src/components/RatingPopup/RatingPopupContainer.jsx

+24-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,41 @@ import {
1111
SET_ACCESS_TOKEN,
1212
} from '../hooks/useAppReducer.js';
1313
import { useRatingPopupReducer } from '../hooks/useRatingPopupReducer.js';
14+
import {
15+
SET_RANDOM_CODES,
16+
STOP_IS_LOADING_FOR_RANDOM_CODES,
17+
} from '../hooks/useRatingPopupReducer.js';
1418

1519
const RatingPopupContainer = ({ appDispatch }) => {
1620
const [state, ratingPopupDispatch] = useRatingPopupReducer();
1721
useWindowWidth(state.innerWidth, ratingPopupDispatch);
18-
const { callRandomCodesAPI } = useRandomCodesAPI(ratingPopupDispatch);
22+
const { callRandomCodesAPI } = useRandomCodesAPI();
1923

2024
console.log('ratingpopup container rendered');
2125

2226
useEffect(() => {
23-
const response = callRandomCodesAPI();
24-
if (response && response.status == 200) {
25-
appDispatch({
26-
type: SET_ACCESS_TOKEN,
27+
const callRandomCodesAPIAndDispatchActions = async () => {
28+
const response = await callRandomCodesAPI();
29+
if (response && response.status == 200) {
30+
appDispatch({
31+
type: SET_ACCESS_TOKEN,
32+
payload: {
33+
accessToken: response['accessToken'],
34+
},
35+
});
36+
}
37+
ratingPopupDispatch({
38+
type: SET_RANDOM_CODES,
2739
payload: {
28-
accessToken: response['accessToken'],
40+
randomCodesResponse: response,
2941
},
3042
});
31-
}
32-
}, [appDispatch, callRandomCodesAPI]);
43+
ratingPopupDispatch({
44+
type: STOP_IS_LOADING_FOR_RANDOM_CODES,
45+
});
46+
};
47+
callRandomCodesAPIAndDispatchActions();
48+
}, [appDispatch, callRandomCodesAPI, ratingPopupDispatch]);
3349

3450
const callRateCodeAPI = useCallback(async (payload) => {
3551
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styles from './ContributionGuidelines.module.css';
2+
3+
const ContributionGuidelines = () => {
4+
return (
5+
<div>
6+
<a
7+
href="https://github.com/TECHOUS/codemash/blob/master/.github/CONTRIBUTING.md"
8+
target="_blank"
9+
rel="noreferrer"
10+
className={styles.link}
11+
>
12+
<i
13+
className={`fa-solid fa-up-right-from-square ${styles.icon}`}
14+
></i>{' '}
15+
Contribution Guidelines
16+
</a>
17+
</div>
18+
);
19+
};
20+
21+
export default ContributionGuidelines;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.link,
2+
.link:visited,
3+
.link:active {
4+
text-decoration: none;
5+
color: var(--void);
6+
}
7+
8+
.icon {
9+
color: var(--psybeam) !important;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ContributionGuidelines from './ContributionGuidelines.jsx';
2+
import styles from './ContributionGuidelinesContainer.module.css';
3+
4+
const ContributionGuidelinesContainer = () => {
5+
return (
6+
<div className={styles.contributionGuidelinesContainer}>
7+
All the Contributions are welcome, you can check our{' '}
8+
<ContributionGuidelines />
9+
</div>
10+
);
11+
};
12+
13+
export default ContributionGuidelinesContainer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.contributionGuidelinesContainer {
2+
font-size: 18px;
3+
text-align: center;
4+
padding: 60px 0px 10px 0px;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './ContributionGuidelinesContainer.jsx';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import PropTypes from 'prop-types';
2+
import styles from './CardContent.module.css';
3+
4+
const CardContent = ({ codeRating, codeName }) => {
5+
return (
6+
<div className={styles.cardContent}>
7+
<h2 className={styles.codeRating}>{codeRating}</h2>
8+
<h3 className={styles.codeName}>{codeName}</h3>
9+
</div>
10+
);
11+
};
12+
13+
CardContent.propTypes = {
14+
codeRating: PropTypes.number,
15+
codeName: PropTypes.string,
16+
};
17+
18+
export default CardContent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.cardContent {
2+
flex: 1;
3+
overflow: hidden;
4+
}
5+
6+
.codeRating {
7+
font-weight: 500;
8+
padding: 16px 0px 0px 0px;
9+
}
10+
11+
.codeName {
12+
font-weight: 500;
13+
padding: 5px 0px 16px 0px;
14+
word-wrap: break-word;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './CardContent.jsx';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import PropTypes from 'prop-types';
2+
import ScoreImoji from '../../ScoreImoji';
3+
import CardContent from './CardContent';
4+
import styles from './ResponseCard.module.css';
5+
6+
const ResponseCard = ({ userCodeBaseFile, searchSectionDispatch }) => {
7+
return (
8+
<div className={styles.responseCard}>
9+
<ScoreImoji
10+
codeRating={userCodeBaseFile.codeRating}
11+
searchSectionDispatch={searchSectionDispatch}
12+
size="fa-3x"
13+
/>
14+
<CardContent
15+
codeRating={userCodeBaseFile.codeRating}
16+
codeName={userCodeBaseFile.codeName}
17+
/>
18+
</div>
19+
);
20+
};
21+
22+
ResponseCard.propTypes = {
23+
userCodeBaseFile: PropTypes.object,
24+
searchSectionDispatch: PropTypes.func,
25+
};
26+
27+
export default ResponseCard;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.responseCard {
2+
background-color: var(--giga);
3+
margin: 10px auto;
4+
border-radius: 10px;
5+
display: flex;
6+
width: 95%;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import PropTypes from 'prop-types';
2+
import ResponseCard from './ResponseCard/ResponseCard.jsx';
3+
4+
const ResponseCards = ({ userCodeBaseFiles, searchSectionDispatch }) => {
5+
return userCodeBaseFiles.map((userCodeBaseFile) => (
6+
<ResponseCard
7+
key={userCodeBaseFile.codeId}
8+
userCodeBaseFile={userCodeBaseFile}
9+
searchSectionDispatch={searchSectionDispatch}
10+
/>
11+
));
12+
};
13+
14+
ResponseCards.propTypes = {
15+
userCodeBaseFiles: PropTypes.array,
16+
searchSectionDispatch: PropTypes.func,
17+
};
18+
19+
export default ResponseCards;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import PropTypes from 'prop-types';
2+
import ResponseCards from './ResponseCards.jsx';
3+
4+
const ResponseCardsContainer = ({
5+
userCodeBaseFiles,
6+
searchSectionDispatch,
7+
}) => {
8+
return (
9+
<div>
10+
<ResponseCards
11+
userCodeBaseFiles={userCodeBaseFiles}
12+
searchSectionDispatch={searchSectionDispatch}
13+
/>
14+
</div>
15+
);
16+
};
17+
18+
ResponseCardsContainer.propTypes = {
19+
userCodeBaseFiles: PropTypes.array,
20+
searchSectionDispatch: PropTypes.func,
21+
};
22+
23+
export default ResponseCardsContainer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './ResponseCardsContainer.jsx';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import PropTypes from 'prop-types';
2+
import DotSpinner from '../../DotSpinner';
3+
import ErrorMessage from '../../ErrorMessage';
4+
import ResponseCards from '../ResponseCards';
5+
import styles from './ResponseHandler.module.css';
6+
7+
const ResponseHandler = ({ state, searchSectionDispatch }) => {
8+
if (state.isSearchResponseLoading) {
9+
return <DotSpinner dotCount={5} />;
10+
} else if (state.searchUserResponse.status === 401) {
11+
return (
12+
<div className={styles.errorMessageContainer}>
13+
<ErrorMessage
14+
errorMessage="Please rate the code again in above section"
15+
iconClasses="fa-solid fa-triangle-exclamation fa-2x"
16+
/>
17+
</div>
18+
);
19+
} else if (
20+
state.searchUserResponse.status === 200 &&
21+
state.searchUserResponse.userCodeBaseFiles.length > 0
22+
) {
23+
return (
24+
<ResponseCards
25+
userCodeBaseFiles={state.searchUserResponse.userCodeBaseFiles}
26+
searchSectionDispatch={searchSectionDispatch}
27+
/>
28+
);
29+
} else {
30+
return (
31+
<div className={styles.errorMessageContainer}>
32+
<ErrorMessage
33+
errorMessage="No results Found !!"
34+
iconClasses="fa-solid fa-poo fa-2x"
35+
/>
36+
</div>
37+
);
38+
}
39+
};
40+
41+
ResponseHandler.propTypes = {
42+
state: PropTypes.object,
43+
searchSectionDispatch: PropTypes.func,
44+
};
45+
46+
export default ResponseHandler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.errorMessageContainer {
2+
padding: 60px 0px 60px 0px;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import PropTypes from 'prop-types';
2+
import { useMemo } from 'react';
3+
import styles from './ScoreImoji.module.css';
4+
5+
const ScoreImoji = ({ codeRating, size }) => {
6+
const computeClassName = useMemo(() => {
7+
let faceClassName = '';
8+
if (codeRating <= -8000) {
9+
faceClassName = 'fa-face-angry';
10+
} else if (codeRating > -8000 && codeRating <= -7000) {
11+
faceClassName = 'fa-face-tired';
12+
} else if (codeRating > -7000 && codeRating <= -6000) {
13+
faceClassName = 'fa-face-dizzy';
14+
} else if (codeRating > -6000 && codeRating <= -5000) {
15+
faceClassName = 'fa-face-grimace';
16+
} else if (codeRating > -5000 && codeRating <= -4000) {
17+
faceClassName = 'fa-face-flushed';
18+
} else if (codeRating > -4000 && codeRating <= -3000) {
19+
faceClassName = 'fa-face-frown-open';
20+
} else if (codeRating > -3000 && codeRating <= -2000) {
21+
faceClassName = 'fa-face-frown';
22+
} else if (codeRating > -2000 && codeRating <= -1000) {
23+
faceClassName = 'fa-face-sad-tear';
24+
} else if (codeRating > -1000 && codeRating <= 0) {
25+
faceClassName = 'fa-face-meh';
26+
} else if (codeRating > 0 && codeRating <= 1000) {
27+
faceClassName = 'fa-face-smile';
28+
} else if (codeRating > 1000 && codeRating <= 2000) {
29+
faceClassName = 'fa-face-smile-beam';
30+
} else if (codeRating > 2000 && codeRating <= 3000) {
31+
faceClassName = 'fa-face-grin';
32+
} else if (codeRating > 3000 && codeRating <= 4000) {
33+
faceClassName = 'fa-face-grin-wide';
34+
} else if (codeRating > 4000 && codeRating <= 5000) {
35+
faceClassName = 'fa-face-grin-beam';
36+
} else if (codeRating > 5000 && codeRating <= 6000) {
37+
faceClassName = 'fa-face-grin-squint';
38+
} else if (codeRating > 6000 && codeRating <= 7000) {
39+
faceClassName = 'fa-face-laugh';
40+
} else if (codeRating > 7000 && codeRating <= 8000) {
41+
faceClassName = 'fa-face-laugh-beam';
42+
} else if (codeRating > 8000 && codeRating <= 9000) {
43+
faceClassName = 'fa-face-laugh-squint';
44+
} else if (codeRating > 9000 && codeRating <= 10000) {
45+
faceClassName = 'fa-face-grin-stars';
46+
} else if (codeRating > 10000) {
47+
faceClassName = 'fa-face-grin-hearts';
48+
}
49+
return `fa-solid ${size} ${faceClassName} ${styles.scoreImojiIcon}`;
50+
}, [codeRating, size]);
51+
52+
return <i className={computeClassName}></i>;
53+
};
54+
55+
ScoreImoji.propTypes = {
56+
codeRating: PropTypes.number,
57+
size: PropTypes.string,
58+
};
59+
60+
export default ScoreImoji;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scoreImojiIcon {
2+
color: var(--psybeam);
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ScoreImoji from './ScoreImoji.jsx';
2+
import PropTypes from 'prop-types';
3+
import { OPEN_SCORE_REACTION_BOARD } from '../../hooks/useSearchSectionReducer.js';
4+
import styles from './ScoreImojiContainer.module.css';
5+
6+
const ScoreImojiContainer = ({ codeRating, searchSectionDispatch, size }) => {
7+
function handleClick() {
8+
searchSectionDispatch({
9+
type: OPEN_SCORE_REACTION_BOARD,
10+
});
11+
}
12+
13+
return (
14+
<div onClick={handleClick} className={styles.scoreImojiContainer}>
15+
<ScoreImoji codeRating={codeRating} size={size} />
16+
</div>
17+
);
18+
};
19+
20+
ScoreImojiContainer.propTypes = {
21+
codeRating: PropTypes.number,
22+
searchSectionDispatch: PropTypes.func,
23+
size: PropTypes.string,
24+
};
25+
26+
export default ScoreImojiContainer;

0 commit comments

Comments
 (0)