Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/SU-ZIP/SUZIP-Frontend in…
Browse files Browse the repository at this point in the history
…to soyeon
  • Loading branch information
hypoxisaurea committed May 31, 2024
2 parents 4b2334f + 49ec050 commit a38a7f7
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/pages/SuzipPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const ContentContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
margin-top: 15vh;
margin-top: 10vh;
`;

const StyledImage = styled.img`
Expand All @@ -119,23 +119,28 @@ const StyledImage = styled.img`
object-fit: contain;
`;

const TitleDateContainer = styled.div<{ imageWidth: number }>`
const TitleDateContainer = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
align-items: center;
margin-top: 10px;
width: ${(props) => props.imageWidth}px;
width: 100%;
margin-bottom: 2vh;
`;

const Title = styled.p`
font-family: "Pretendard";
font-size: 1.2em;
font-size: 1.3em;
margin: 0;
text-align: center;
font-weight: 500;
`;

const DateText = styled.p`
font-family: "Pretendard";
font-size: 1.1em;
margin: 0;
text-align: center;
`;

const NoImageText = styled.div`
Expand All @@ -149,8 +154,6 @@ const SuzipPage: React.FC = () => {
const [diaryDate, setDiaryDate] = useState("");
const [diaryTitle, setDiaryTitle] = useState("");
const [scrollY, setScrollY] = useState(0);
const [imageWidth, setImageWidth] = useState(0);
const imageRef = useRef<HTMLImageElement>(null);
const navigate = useNavigate(); // useNavigate 훅 사용

const fetchDiaryData = async () => {
Expand Down Expand Up @@ -202,22 +205,6 @@ const SuzipPage: React.FC = () => {
return () => window.removeEventListener("scroll", handleScroll);
}, []);

useEffect(() => {
if (imageRef.current) {
const handleResize = () => {
if (imageRef.current) {
const width = imageRef.current.getBoundingClientRect().width;
setImageWidth(width);
console.log("Image width:", width);
}
};

handleResize(); // Initial call to set the width
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}
}, [diaryImage]);

return (
<PageContainer>
<Frame1Container>
Expand All @@ -239,16 +226,16 @@ const SuzipPage: React.FC = () => {
<ContentContainer>
{diaryImage ? (
<>
<StyledImage src={diaryImage} alt="Diary Image" ref={imageRef} />
<TitleDateContainer imageWidth={imageWidth}>
<TitleDateContainer>
<Title>{diaryTitle}</Title>
<DateText>{diaryDate}</DateText>
</TitleDateContainer>
<StyledImage src={diaryImage} alt="Diary Image" />
</>
) : (
<>
<NoImageText>No Image</NoImageText>
<TitleDateContainer imageWidth={imageWidth}>
<TitleDateContainer>
<Title>{diaryTitle}</Title>
<DateText>{diaryDate}</DateText>
</TitleDateContainer>
Expand Down

0 comments on commit a38a7f7

Please sign in to comment.