Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #19 🎫: Refactor to migrate es6 FC to es5 FC - and - Fix 'LikeButton' UI FC non-persistend liked style #20

Merged
merged 5 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 31 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.0",
"eslint-plugin-react-hooks": "^4.6.0",
"gh-pages": "^5.0.0",
"gh-pages": "^6.1.1",
"sass": "^1.66.1",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^21.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/UI/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../styles/UI/ContactForm.scss';

const successButtonIcon = 'https://camo.githubusercontent.com/b55970b1d4c6e5d8d09a07556bce08ff3cfec080b680ad6b5be3ed46546e6f77/68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6b52654b6366727331596f546d74324151742f67697068792e676966';

const ContactForm: React.FC = () => {
function ContactForm(): React.ReactElement {
const [formContent, setFormContent] = useState(
JSON.parse(sessionStorage.getItem('formContent')!) || null,
// * ! = non-null assertion operator to tell TS that
Expand Down Expand Up @@ -313,6 +313,6 @@ const ContactForm: React.FC = () => {
)}
</form>
);
};
}

export default ContactForm;
70 changes: 36 additions & 34 deletions src/components/UI/ExpertiseLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@ import { Link } from 'react-router-dom';

import '../../styles/UI/ExpertiseLinks.scss';

const ExpertiseLinks: React.FC = () => (
<div className="expertise-links">
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
languages
</Link>
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
frameworks
</Link>
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
skills
</Link>
<a
href="https://docs.google.com/document/d/1vfOALwpILAh8Jn29zV6aO6jwuGZQwLyYjRb3_YKZfQ0/edit?usp=sharing"
className="text-hue-rotate"
aria-label="navigate to Arthur's resume which is hosted on Google Docs"
target="_blank"
rel="noreferrer noopener"
>
resume
</a>
</div>
);
function ExpertiseLinks(): React.ReactElement {
return (
<div className="expertise-links">
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
languages
</Link>
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
frameworks
</Link>
<Link
to="/homepage/expertise"
className="text-hue-rotate"
aria-label="navigate to expertise section"
>
skills
</Link>
<a
href="https://docs.google.com/document/d/1vfOALwpILAh8Jn29zV6aO6jwuGZQwLyYjRb3_YKZfQ0/edit?usp=sharing"
className="text-hue-rotate"
aria-label="navigate to Arthur's resume which is hosted on Google Docs"
target="_blank"
rel="noreferrer noopener"
>
resume
</a>
</div>
);
}

export default ExpertiseLinks;
4 changes: 2 additions & 2 deletions src/components/UI/FileTabsNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FaReact } from 'react-icons/fa';

import '../../styles/UI/FileTabsNavbar.scss';

const FileTabsNavbar: React.FC = () => {
function FileTabsNavbar(): React.ReactElement {
const iconSize = 26;

const { pathname } = useLocation();
Expand Down Expand Up @@ -74,6 +74,6 @@ const FileTabsNavbar: React.FC = () => {
</ul>
</nav>
);
};
}

export default FileTabsNavbar;
14 changes: 9 additions & 5 deletions src/components/UI/LikeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ interface LikeButtonProps {
projectsLikes: Like[];
}

const LikeButton: React.FC<LikeButtonProps> = ({ itemId, projectsLikes }) => {
function LikeButton(props: LikeButtonProps): React.ReactElement {
const { itemId, projectsLikes } = props;

const [wasLiked, setWasLiked] = useState(false);
const [likeCount, setLikeCount] = useState(0);
const [error, setError] = useState(false);
Expand All @@ -36,7 +38,7 @@ const LikeButton: React.FC<LikeButtonProps> = ({ itemId, projectsLikes }) => {

const styleButton = useCallback(() => {
if (wasLiked) {
likeBtn.current?.classList.toggle('liked');
likeBtn.current?.classList.add('liked');
}
}, [wasLiked]);

Expand Down Expand Up @@ -98,13 +100,15 @@ const LikeButton: React.FC<LikeButtonProps> = ({ itemId, projectsLikes }) => {
const handleLikeSubmit = async () => {
// ? Since 'wasLiked' was false, now it will be set to true. This is to
// ? trigger the function 'styleButton' to add the 'liked' class to the button.
setWasLiked((wasLiked) => !wasLiked);
setWasLiked(true);

// * shows an instant update of the like count.
if (!wasLiked) {
setLikeCount((count) => count + 1);
// * set 'wasLiked' to false, so that the user can like the project again.
setWasLiked((wasLiked) => !wasLiked);
setTimeout(() => {
setWasLiked(false);
}, 1000);
}

if (projectsLikes[0].error || error) {
Expand Down Expand Up @@ -164,6 +168,6 @@ const LikeButton: React.FC<LikeButtonProps> = ({ itemId, projectsLikes }) => {
)}
</button>
);
};
}

export default LikeButton;
4 changes: 2 additions & 2 deletions src/components/UI/LineCount.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';

const LineCount: React.FC = () => {
function LineCount(): React.ReactElement {
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
const spanHeight = 24; // ? 24px.

Expand Down Expand Up @@ -29,6 +29,6 @@ const LineCount: React.FC = () => {
))}
</div>
);
};
}

export default LineCount;
Loading
Loading