Skip to content

Commit

Permalink
Layout fixes (#1985)
Browse files Browse the repository at this point in the history
* Layout fixes

* Remove hardcoded totalDays
  • Loading branch information
aweell authored Nov 28, 2024
1 parent 9910f6c commit a3e9f01
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
54 changes: 28 additions & 26 deletions src/pages/advent-calendar-2024/components/calendar-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Text,
Text5,
} from "@telefonica/mistica";
import { useRef, useState } from "react";
import { useRef, useState, useEffect } from "react";
import { IconCompleted, IconLockOpen } from "../assets/icons/icons";
import { CARD_STATES } from "../utils/constants";
import styles from "./calendar-card.module.css";
Expand All @@ -26,36 +26,37 @@ const CalendarCard = ({
repeatable,
}) => {
const [isHovered, setIsHovered] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const dialogRef = useRef(null);
const day = new Date(DateString).getDate();
const today = new Date().getDate();
const isRepeatable =
repeatable &&
DateString === today &&
(status === CARD_STATES.AVAILABLE || status === CARD_STATES.COMPLETED);
const isRepeatable = repeatable && DateString === today;

const handleClick = () => {
if (status === CARD_STATES.AVAILABLE || isRepeatable) {
dialogRef.current.showModal();
document.body.style.overflow = "hidden";
setIsModalOpen((prev) => !prev); // Toggle modal state
}
};

// Effect to show the modal when `isModalOpen` is true
useEffect(() => {
if (isModalOpen) {
dialogRef.current?.showModal();
}
}, [isModalOpen]);

const handleEndDay = () => {
dialogRef.current.close();
document.body.style.overflow = "auto";
onEndDay(); // Notify the parent to update the state
};

const handleCloseModal = () => {
dialogRef.current.close(); // Close the modal
document.body.style.overflow = "auto";
onEndDay(); // Notify the parent to update the state
};

const handleDismiss = () => {
dialogRef.current.close();
document.body.style.overflow = "auto";
};

let cardStatusStyles;
Expand Down Expand Up @@ -155,7 +156,7 @@ const CalendarCard = ({
style={{
cursor:
status !== CARD_STATES.AVAILABLE && !isRepeatable
? "not-allowed"
? "inherit"
: "pointer",

padding: 24,
Expand Down Expand Up @@ -202,7 +203,6 @@ const CalendarCard = ({
}
>
{DayOfWeek}
{isRepeatable && "isRepeatable"}
</Text5>

<StatusIndicator />
Expand Down Expand Up @@ -236,20 +236,22 @@ const CalendarCard = ({
</Inline>
</Stack>
</button>
<ModalView
ref={dialogRef}
day={day}
dayOfWeek={DayOfWeek}
title={eventName}
description={eventDescription}
content={
typeof content === "function"
? content({ closeModal: handleCloseModal })
: content
}
onClose={handleEndDay}
onCancel={repeatable ? handleEndDay : handleDismiss}
/>
{isModalOpen && (
<ModalView
ref={dialogRef}
day={day}
dayOfWeek={DayOfWeek}
title={eventName}
description={eventDescription}
content={
typeof content === "function"
? content({ closeModal: handleCloseModal })
: content
}
onClose={handleEndDay}
onCancel={repeatable ? handleEndDay : handleDismiss}
/>
)}
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/pages/advent-calendar-2024/components/game-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const GameBar = ({ score, time, timeRunning, movements }) => {
left: isMobile ? 0 : 56,
top: isMobile ? 0 : 56,
marginBottom: isMobile ? 24 : 0,
zIndex: 2,
}}
>
<Score
Expand Down
48 changes: 22 additions & 26 deletions src/pages/advent-calendar-2024/components/modal-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import {
import { DecorationSnake } from "../assets/decorations/decorations";

const ModalView = forwardRef(
({ title, day, dayOfWeek, description, content, onCancel, repeatable }, ref) => {
const { isMobile } = useScreenSize();
(
{ title, day, dayOfWeek, description, content, onCancel, repeatable },
ref
) => {
const { isMobile, isLargeDesktop } = useScreenSize();

return (
<dialog
Expand Down Expand Up @@ -55,35 +58,28 @@ const ModalView = forwardRef(
position: "relative",
display: "flex",
flexDirection: "column",
justifyContent: "center",
justifyContent: "space-around",
gap: isMobile ? "16px" : "56px",
}}
>
<div
style={{
position: isMobile ? "inherit" : "absolute",
paddingBottom: "16px",
top: isMobile ? 0 : 64,
left: isMobile ? 0 : 64,
}}
>
<Stack space={0}>
<Text
color={skinVars.colors.brand}
size={isMobile ? 24 : 60}
weight="bold"
>
{day}
</Text>
<Text4 color={skinVars.colors.brand} weight="medium">
{dayOfWeek}
</Text4>{" "}
</Stack>
</div>
<Stack space={0}>
<Text
color={skinVars.colors.brand}
size={isMobile ? 24 : 60}
weight="bold"
>
{day}
</Text>
<Text4 color={skinVars.colors.brand} weight="medium">
{dayOfWeek}
</Text4>{" "}
</Stack>

<Stack space={24}>
<Text
color={skinVars.colors.brand}
size={isMobile ? 32 : 80}
lineHeight={isMobile ? 34 : 80}
size={isMobile ? 32 : isLargeDesktop ? 80 : 64}
lineHeight={isMobile ? 34 : isLargeDesktop ? 80 : 64}
weight="bold"
>
{title}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/advent-calendar-2024/pages/progress-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getAchievementFromLocalStorage,
} from "../utils/achievement-config";
import { TOTAL_CALENDAR_DAYS } from "../utils/constants";
import { calendarDays } from "../utils/calendar-config.jsx";

const ProgressView = () => {
const [completedDays, setCompletedDays] = useState([]);
Expand Down Expand Up @@ -181,7 +182,7 @@ const ProgressView = () => {
<Text size={64} mobileSize={48} lineHeight={64} mobileLineHeight={48}>
of
</Text>{" "}
{TOTAL_CALENDAR_DAYS}
{calendarDays.length}
</Text>
<Stack space={4}>
<Inline space={8} alignItems="center">
Expand Down

0 comments on commit a3e9f01

Please sign in to comment.