add minimum load time to the UI on toggling a like

This commit is contained in:
erik-sn committed 2020-10-05 21:56:03 -04:00
1 parent bb23413533
commit c2e1f17f3b
2 files changed
+23 -3

No files matched your search

@@ -1,18 +1,33 @@
import React, { useState, useEffect } from "react"; import React, { useState } from "react";
import { Button } from "@material-ui/core"; import { Button, CircularProgress } from "@material-ui/core";
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder"; import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
import FavoriteIcon from "@material-ui/icons/Favorite"; import FavoriteIcon from "@material-ui/icons/Favorite";
import Nui from "../../../../os/nui-events/utils/Nui"; import Nui from "../../../../os/nui-events/utils/Nui";
const LOADING_TIME = 1250;
function LikeButton({ tweetId, isLiked }) { function LikeButton({ tweetId, isLiked }) {
const [liked, setLiked] = useState(isLiked); const [liked, setLiked] = useState(isLiked);
const [loading, setLoading] = useState(false);
const handleClick = () => { const handleClick = () => {
Nui.send("phone:toggleLike", tweetId); Nui.send("phone:toggleLike", tweetId);
setLiked(!liked); setLoading(true);
window.setTimeout(() => {
setLiked(!liked);
setLoading(false);
}, LOADING_TIME);
}; };
if (loading) {
return (
<Button disabled>
<CircularProgress size={22} />
</Button>
);
}
return ( return (
<Button onClick={handleClick}> <Button onClick={handleClick}>
{liked ? <FavoriteIcon /> : <FavoriteBorderIcon />} {liked ? <FavoriteIcon /> : <FavoriteBorderIcon />}
@@ -25,6 +25,11 @@ some of the Material UI primary theme settings */
border-bottom-color: #00acee !important; border-bottom-color: #00acee !important;
} }
/* override circular progress on the likes button */
#twitter-app .MuiCircularProgress-colorPrimary {
color: #00acee !important;
}
/* /*
override position of the snackbar so that it appears override position of the snackbar so that it appears
within the phone rather than on the game UI */ within the phone rather than on the game UI */