Skip to content

Commit

Permalink
Refactor disabled illustrations logic and fix JS errors (#1982)
Browse files Browse the repository at this point in the history
* JS fixes and small refactor

* unused type

* remove warnings

* render snow behind content
  • Loading branch information
marcoskolodny authored Nov 26, 2024
1 parent ba8d2e8 commit 347cbe2
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 166 deletions.
19 changes: 5 additions & 14 deletions src/pages/advent-calendar-2024/components/calendar-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const CalendarCard = ({
content,
status,
onEndDay,
illustration,
illustrationDimmed,
Illustration,
repeatable,
}) => {
const [isHovered, setIsHovered] = useState(false);
Expand Down Expand Up @@ -84,11 +83,7 @@ const CalendarCard = ({
}
}

const IllustrationWrapper = ({
illustration,
illustrationDimmed,
status,
}) => {
const IllustrationWrapper = ({ Illustration, status }) => {
return (
<div
style={{
Expand All @@ -97,7 +92,7 @@ const CalendarCard = ({
justifyContent: "center",
}}
>
{status === CARD_STATES.BLOCKED ? illustrationDimmed : illustration}
<Illustration disabled={status === CARD_STATES.BLOCKED} />
</div>
);
};
Expand Down Expand Up @@ -213,12 +208,8 @@ const CalendarCard = ({
<StatusIndicator />
</Stack>

{(illustration || illustrationDimmed) && (
<IllustrationWrapper
illustration={illustration}
illustrationDimmed={illustrationDimmed}
status={status}
/>
{Illustration && (
<IllustrationWrapper Illustration={Illustration} status={status} />
)}

<Inline space="between" alignItems="center">
Expand Down
4 changes: 0 additions & 4 deletions src/pages/advent-calendar-2024/components/corner-layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ import {
useScreenSize,
} from "@telefonica/mistica";
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { base64Encode } from "../utils/url-encoder";
import RotatingSVG from "./label-rotate";

const CornerLayout = () => {
const navigate = useNavigate();
const location = useLocation(); // Get the current location
const { isLargeDesktop, isTabletOrBigger } = useScreenSize();
const [isSnackbarOpen, setSnackbarOpen] = useState(false);
const [showLogo, setShowLogo] = useState(false);
Expand Down
4 changes: 1 addition & 3 deletions src/pages/advent-calendar-2024/components/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
useScreenSize,
} from "@telefonica/mistica";
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { base64Encode } from "../utils/url-encoder";
import { useLocation } from "react-router-dom";
import RotatingSVG from "./label-rotate";

const SheetView = ({ isOpen, onClose }) => {
Expand Down Expand Up @@ -100,7 +99,6 @@ const SheetView = ({ isOpen, onClose }) => {
};

const NavBar = () => {
const navigate = useNavigate();
const location = useLocation(); // Get the current location
const { isMobile, isTabletOrSmaller } = useScreenSize();
const [isSheetOpen, setIsSheetOpen] = useState(false);
Expand Down
13 changes: 5 additions & 8 deletions src/pages/advent-calendar-2024/components/progress-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CARD_STATES } from "../utils/constants"; // Importa CARD_STATES si no l
import contentByDate from "../utils/content-config"; // Asegúrate de importar tu configuración de contenido

// IllustrationWrapper Component
const IllustrationWrapper = ({ illustration, illustrationDimmed, status }) => {
const IllustrationWrapper = ({ Illustration, status }) => {
return (
<Align x="center">
<div
Expand All @@ -28,7 +28,7 @@ const IllustrationWrapper = ({ illustration, illustrationDimmed, status }) => {
height: "100px",
}}
>
{status === CARD_STATES.BLOCKED ? illustrationDimmed : illustration}
<Illustration disabled={status === CARD_STATES.BLOCKED} />
</div>
</Align>
);
Expand Down Expand Up @@ -62,7 +62,7 @@ const ProgressGrid = ({ completedDays }) => {
<Grid columns={isMobile ? 2 : 4} gap={isMobile ? 8 : 24}>
{calendarDays.map((day) => {
// Accede a la ilustración para cada día
const illustration = contentByDate[day.date]?.illustration;
const Illustration = contentByDate[day.date]?.Illustration;

// Determina el estado del día
const status = isDayCompleted(day.dayNumber)
Expand All @@ -88,12 +88,9 @@ const ProgressGrid = ({ completedDays }) => {
</div>

{/* Renderiza la ilustración usando IllustrationWrapper */}
{illustration ? (
{Illustration ? (
<IllustrationWrapper
illustration={illustration}
illustrationDimmed={
contentByDate[day.date]?.illustrationDimmed
}
Illustration={Illustration}
status={status}
/>
) : (
Expand Down
8 changes: 6 additions & 2 deletions src/pages/advent-calendar-2024/components/score.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
IconAlarmClockFilled,
Inline,
skinVars,
Tag,
Text4,
Expand All @@ -16,7 +15,12 @@ const Score = ({ score, time, timeRunning, movements, isFinal }) => {
style={{ display: "inline-flex", flexDirection: "column", gap: 8 }}
>
<Text5>Your final score is</Text5>
<DecorationPatty size={128} text={score} stroke="0.75" color={skinVars.colors.brand} />
<DecorationPatty
size={128}
text={score}
stroke="0.75"
color={skinVars.colors.brand}
/>
</div>
) : (
<div style={{ display: "flex", gap: 24 }}>
Expand Down
36 changes: 10 additions & 26 deletions src/pages/advent-calendar-2024/components/snow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import Snowfall from "react-snowfall";
import { useEffect, useState } from "react";
import snowflakeSrc1 from "../assets/decorations/snowflake-1.svg";
Expand Down Expand Up @@ -49,31 +48,16 @@ const Snow = () => {
};
}, []);

return isTabletOrSmaller ? (
<Snowfall
style={{
position: "fixed",
zIndex: "9999999",
}}
color="#EEF0FB"
radius={[30, 30]}
speed={[1.0, 2.0]} // Velocidad de los copos
snowflakeCount={8}
images={images} // Pasamos las imágenes cargadas al componente
/>
) : (
<Snowfall
style={{
position: "fixed",
zIndex: "9999999",
}}
color="#EEF0FB"
radius={[50, 50]}
speed={[1.0, 2.0]} // Velocidad de los copos
snowflakeCount={20}
images={images} // Pasamos las imágenes cargadas al componente
/>
);
return Snowfall({
style: {
position: "fixed",
},
color: "#EEF0FB",
radius: isTabletOrSmaller ? [30, 30] : [50, 50],
speed: [1, 2], // Velocidad de los copos
snowflakeCount: isTabletOrSmaller ? 8 : 20,
images, // Pasamos las imágenes cargadas al componente
});
};

export default Snow;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import ContentWrapper from "../content-wrapper";
import contentByDate from "../../utils/content-config";

const ChristmasGreetings = () => {
const FinalIllustration = contentByDate["2024-12-25"].Illustration;
return (
<ContentWrapper textAlign={"center"}>
<Stack space={52}>
<div>{contentByDate["2024-12-25"].illustration}</div>
<FinalIllustration />
<Text5>
Thanks for joining us these past days.
<br></br>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/advent-calendar-2024/components/toast-wrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState, useEffect } from "react";
import Toast from "./toast"; // Assuming your Toast component is already implemented
import { Stack, useScreenSize } from "@telefonica/mistica";

Expand All @@ -17,8 +16,6 @@ const ToastWrapper = ({ toasts, removeToast }) => {
>
<Stack space={8}>
{toasts.map((toast, index) => {
const scaleValue = 1 - index * 0.2;

return (
<Toast
id={toast.id}
Expand Down
18 changes: 9 additions & 9 deletions src/pages/advent-calendar-2024/components/toast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ const Toast = ({
}
};

const startHideTimeout = () => {
clearHideTimeout();
timeoutRef.current = setTimeout(() => {
setFadeOut(true); // Trigger fade-out before setting visible to false
onClose?.(); // Trigger onClose callback to remove toast
}, duration);
};

// Handle visibility change when hovered or not
useEffect(() => {
const startHideTimeout = () => {
clearHideTimeout();
timeoutRef.current = setTimeout(() => {
setFadeOut(true); // Trigger fade-out before setting visible to false
onClose?.(); // Trigger onClose callback to remove toast
}, duration);
};

const handleTimeout = () => {
if (!isHovered) {
setTimeout(startHideTimeout, delay); // Delay before auto-dismissing
Expand All @@ -57,7 +57,7 @@ const Toast = ({
handleTimeout();

return () => clearHideTimeout(); // Cleanup timeout on unmount
}, [isHovered, delay, duration]);
}, [isHovered, delay, duration, onClose]);

useEffect(() => {
if (fadeOut) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/advent-calendar-2024/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import CalendarView from "./pages/calendar-view";

import { RELEASE_DATE } from "./utils/constants";

const AdventCalendar2024 = () => {
const targetDate = new Date(RELEASE_DATE);
const targetDate = new Date(RELEASE_DATE);

const AdventCalendar2024 = () => {
const [isReleased, setIsReleased] = useState(false);

useLayoutEffect(() => {
Expand All @@ -23,7 +23,7 @@ const AdventCalendar2024 = () => {
}, timeToRelease);

return () => clearTimeout(timeout);
}, [targetDate]);
}, []);

if (!isReleased) {
return <ComingSoonPage targetDate={targetDate.toLocaleString()} />;
Expand Down
58 changes: 25 additions & 33 deletions src/pages/advent-calendar-2024/pages/calendar-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
skinVars,
useScreenSize,
} from "@telefonica/mistica";
import { useMemo, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { useState } from "react";
import DecorationPatty from "../assets/decorations/decoration-patty.jsx";
import DecorationSnake from "../assets/decorations/decoration-snake.jsx";
import CalendarCard from "../components/calendar-card";
Expand All @@ -36,7 +35,6 @@ import { calendarDays } from "../utils/calendar-config.jsx";
import { CARD_STATES } from "../utils/constants";
import contentByDate from "../utils/content-config";
import { updateCompletedDays } from "../utils/state-manager";
import { base64Encode } from "../utils/url-encoder.jsx";

const CalendarView = () => {
const { isMobile } = useScreenSize();
Expand Down Expand Up @@ -123,26 +121,20 @@ const CalendarView = () => {
}
};

const calendarItems = useMemo(() => {
return calendarDays.map(({ date, dayOfWeek }) => (
<CalendarCard
key={date}
DateString={date}
DayOfWeek={dayOfWeek}
eventName={contentByDate[date]?.title}
eventDescription={contentByDate[date]?.description}
content={contentByDate[date]?.content}
status={getDayStatus(date)} // Ensure status is updated based on availability
onEndDay={() => markDayAsCompleted(date)}
illustration={contentByDate[date]?.illustration}
illustrationDimmed={
contentByDate[date]?.illustrationDimmed ||
contentByDate[date]?.illustration
}
repeatable={contentByDate[date]?.repeatable}
/>
));
}, [completedDays, availableDays, calendarDays]);
const calendarItems = calendarDays.map(({ date, dayOfWeek }) => (
<CalendarCard
key={date}
DateString={date}
DayOfWeek={dayOfWeek}
eventName={contentByDate[date]?.title}
eventDescription={contentByDate[date]?.description}
content={contentByDate[date]?.content}
status={getDayStatus(date)} // Ensure status is updated based on availability
onEndDay={() => markDayAsCompleted(date)}
Illustration={contentByDate[date]?.Illustration}
repeatable={contentByDate[date]?.repeatable}
/>
));
const [isSheetOpen, setIsSheetOpen] = useState(false);

const SheetView = ({ isOpen, onClose }) => {
Expand Down Expand Up @@ -228,11 +220,11 @@ const CalendarView = () => {
};

return (
<>
<ResponsiveLayout>
<Snow />
<CornerLayout />
<NavBar />
<ResponsiveLayout>
<div style={{ position: "relative", zIndex: 1 }}>
<CornerLayout />
<NavBar />
<Box paddingY={42}>
<Stack space={48}>
<GridLayout
Expand Down Expand Up @@ -277,7 +269,7 @@ const CalendarView = () => {
textColor={skinVars.colors.textPrimary}
textSize={16}
easterEgg={true}
></DecorationPatty>
/>
</Inline>
<DecorationSnake width={isMobile ? "100%" : 371.84} />
</Stack>
Expand All @@ -297,7 +289,7 @@ const CalendarView = () => {
</Text4>
</Stack>
}
></GridLayout>
/>

<Carousel
initialActiveItem={initialActiveDay}
Expand All @@ -311,10 +303,10 @@ const CalendarView = () => {
</ButtonPrimary>
</Stack>
</Box>
</ResponsiveLayout>
<SheetView isOpen={isSheetOpen} onClose={() => setIsSheetOpen(false)} />
<ToastWrapper toasts={toasts} removeToast={removeToast} />
</>
<SheetView isOpen={isSheetOpen} onClose={() => setIsSheetOpen(false)} />
<ToastWrapper toasts={toasts} removeToast={removeToast} />
</div>
</ResponsiveLayout>
);
};

Expand Down
Loading

0 comments on commit 347cbe2

Please sign in to comment.