Skip to content

Commit

Permalink
画像のローディング実装
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Dec 29, 2024
1 parent d07e6ff commit d1defc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
63 changes: 41 additions & 22 deletions src/Components/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { useUser } from "@/utils/UserContext";
import AppRegistrationRoundedIcon from "@mui/icons-material/AppRegistrationRounded";
import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
import CloseIcon from "@mui/icons-material/Close";
import { CssVarsProvider, Divider, extendTheme } from "@mui/joy";
import Card from "@mui/joy/Card";
import CardContent from "@mui/joy/CardContent";
import Skeleton from "@mui/joy/Skeleton";
import Step, { stepClasses } from "@mui/joy/Step";
import StepIndicator, { stepIndicatorClasses } from "@mui/joy/StepIndicator";
import Stepper from "@mui/joy/Stepper";
import Typography, { typographyClasses } from "@mui/joy/Typography";
import { Divider } from "@mui/material";
import { getDownloadURL, getStorage, ref } from "firebase/storage";
import { ReactNode, useState } from "react";
import DeleteGoalModal from "../DeleteGoalModal/DeleteGoalModal";
Expand Down Expand Up @@ -117,7 +118,7 @@ const SuccessStep = ({
user: User;
}) => {
const [imageURL, setImageURL] = useState("");
const [imageLoading, setImageLoading] = useState(true);
const [imageLoaded, setImageLoaded] = useState(false);

const post = result.post;
if (!post) {
Expand All @@ -129,14 +130,22 @@ const SuccessStep = ({

getDownloadURL(imageRef)
.then((url) => {
console.log("Image URL:", url);
setImageURL(url);
setImageLoading(false);
})
.catch((error) => {
console.error("Error fetching image URL:", error);
});

const theme = extendTheme({
components: {
JoySkeleton: {
defaultProps: {
animation: "wave",
},
},
},
});

return (
<StepperBlock
key={result.goalId}
Expand Down Expand Up @@ -181,23 +190,33 @@ const SuccessStep = ({
zIndex: 0,
}}
>
{!imageLoading && (
<img
src={imageURL}
srcSet={imageURL}
style={{
objectFit: "contain",
maxWidth: "100%",
maxHeight: "50vh",
borderRadius: "5px 5px 0 0",
}}
loading="lazy"
alt=""
/>
)}
<CardContent
sx={{ padding: "10px", borderTop: "thin solid #cdcdcd" }}
>
<div style={{ minHeight: "15vh" }}>
<CssVarsProvider theme={theme}>
<Skeleton
loading={!imageLoaded}
variant="overlay"
sx={{ borderRadius: "5px 5px 0 0", height: "15vh" }}
>
{imageURL && (
<img
src={imageURL}
srcSet={imageURL}
style={{
objectFit: "contain",
maxWidth: "100%",
maxHeight: "50vh",
borderRadius: "5px 5px 0 0",
borderBottom: "thin solid #cdcdcd",
}}
loading="lazy"
alt=""
onLoad={() => setImageLoaded(true)}
/>
)}
</Skeleton>
</CssVarsProvider>
</div>
<CardContent sx={{ padding: "0 10px 10px" }}>
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Typography level="body-sm">
{formatStringToDate(post.submittedAt)}に完了
Expand Down Expand Up @@ -379,7 +398,7 @@ const StepperBlock = ({
sx={{
width: "87%",
margin: "10px auto",
padding: "13px",
padding: "10px 13px",
borderRadius: "8px",
border: "1px solid",
borderColor:
Expand Down
2 changes: 1 addition & 1 deletion src/styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ body {

main {
background: white;
padding-bottom: 100px;
padding-bottom: 130px;
}

0 comments on commit d1defc2

Please sign in to comment.