Skip to content

Commit

Permalink
Merge pull request #77 from green-ecolution/feature/change-cookie-to-…
Browse files Browse the repository at this point in the history
…local-storage

feat: change cookie to localStorage
  • Loading branch information
choffmann authored Jul 30, 2024
2 parents c0f8589 + ffa8852 commit d1b889b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
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";
}

0 comments on commit d1b889b

Please sign in to comment.