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: 첫 방문 사용자 about페이지로 리다이렉트 #324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { lazy, Suspense, useEffect } from "react";
import { Routes, Route, useLocation } from "react-router-dom";
import { Routes, Route, useLocation, Navigate } from "react-router-dom";

import PostDetail from "@/components/common/Card/PostDetail";
import { Toaster } from "@/components/ui/toaster";
Expand All @@ -15,6 +15,7 @@ import { useMediaQuery } from "@/hooks/common/useMediaQuery";
import { denamuAscii } from "@/constants/denamuAscii";

import { useMediaStore } from "@/store/useMediaStore";
import { useVisitStore } from "@/store/useVisitStore";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

Expand All @@ -27,6 +28,7 @@ const queryClient = new QueryClient();
export default function App() {
const setIsMobile = useMediaStore((state) => state.setIsMobile);
const isMobile = useMediaQuery("(max-width: 767px)");
const { hasVisited, setVisited } = useVisitStore();
const location = useLocation();
const state =
location.state && location.state.backgroundLocation
Expand All @@ -46,7 +48,10 @@ export default function App() {
useEffect(() => {
setIsMobile(isMobile);
}, [isMobile]);

if (!hasVisited) {
setVisited();
return <Navigate to="/about" replace />;
}
return (
<QueryClientProvider client={queryClient}>
<Routes location={state?.backgroundLocation || location}>
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/sections/MainContent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useEffect } from "react";

import LatestSection from "@/components/sections/LatestSection";
import TrandingSection from "@/components/sections/TrendingSection";

import { useMediaStore } from "@/store/useMediaStore";

export default function MainContent() {
const isMobile = useMediaStore((state) => state.isMobile);
useEffect(() => {
window.scrollTo(0, 0);
}, []);
return (
<div className="flex flex-col px-4 md:p-8 md:gap-8">
<TrandingSection />
Expand Down
21 changes: 21 additions & 0 deletions client/src/store/useVisitStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { create } from "zustand";

import { persist, createJSONStorage } from "zustand/middleware";

interface VisitState {
hasVisited: boolean;
setVisited: () => void;
}

export const useVisitStore = create<VisitState>()(
persist(
(set) => ({
hasVisited: false,
setVisited: () => set({ hasVisited: true }),
}),
{
name: "visit-flag",
storage: createJSONStorage(() => localStorage),
}
)
);
Loading