Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change cookie to localStorage #77

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tsx/components/cards/WelcomeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Arrow from '../../icons/Arrow';
import Lottie from 'lottie-react';
import logoAnimation from '../../../json/logoAnimation.json';
import { useOutsideClick } from '../../hooks/useOutsideClick';
import { hasCookie } from '../../helper/cookies';
import { isInitialLoad } from '../../helper/storage';

interface WelcomeCardProps {
onClose: () => void;
Expand All @@ -29,7 +29,7 @@ const WelcomeCard: React.FC<WelcomeCardProps> = ({ onClose, handleStartAnmiation
};

useEffect(() => {
if (! hasCookie('green_ecolution_initial_load') && isOverlayVisible) {
if (isInitialLoad() && isOverlayVisible) {
const timer = setTimeout(() => { setIsVisible(true) }, delay + 200);
return () => clearTimeout(timer);
}
Expand Down
10 changes: 5 additions & 5 deletions src/tsx/components/homepage/HomepageHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
import Arrow from "../../icons/Arrow";
import HomepageOverlay from "./HomepageOverlay";
import HomepageHeroTrees from "./HomepageHeroTrees";
import { setCookie, hasCookie } from "../../helper/cookies";
import { setInitialLoad as setInitialLoadHelper, isInitialLoad as isInitialLoadHelper } from "../../helper/storage";

function HomepageHero() {
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
Expand All @@ -14,7 +14,7 @@ function HomepageHero() {

if (isInitialLoad) {
setIsInitialLoad(false);
setCookie('green_ecolution_initial_load');
setInitialLoadHelper();
}
};

Expand All @@ -41,8 +41,8 @@ function HomepageHero() {
}, [isOverlayVisible]);

useEffect(() => {
if (! hasCookie('green_ecolution_initial_load')
&& ! isOverlayVisible
if (isInitialLoadHelper()
&& !isOverlayVisible
&& window.matchMedia('(min-width: 1280px)').matches
) {
setIsInitialLoad(true);
Expand Down Expand Up @@ -76,7 +76,7 @@ function HomepageHero() {
</p>
<button
className={`hidden items-center justify-center gap-x-4 rounded-2xl w-max font-semibold px-5 py-2 group bg-green-light-900 transition-color ease-in-out duration-300 text-white hover:bg-green-middle-900 hover:border-green-middle-900
${hasCookie('green_ecolution_initial_load') ? 'xl:flex' : '' }`}
${!isInitialLoadHelper() ? 'xl:flex' : '' }`}
onClick={handleOpenOverlay}
>
Animation abspielen
Expand Down
32 changes: 0 additions & 32 deletions src/tsx/helper/cookies.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/tsx/helper/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function setInitialLoad() {
localStorage.setItem("green_ecolution_initial_load", "false");
}

export function isInitialLoad(): boolean {
return localStorage.getItem("green_ecolution_initial_load") !== "false";
}
Loading