Skip to content

Commit 011ba8b

Browse files
committed
Fix: storage issue overwriting refresh on page.
1 parent a4bd62a commit 011ba8b

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Home from './pages/home/Home';
55
import Explore from './pages/Explore';
66
import Chat from './pages/Chat';
77
import { RocketTransition } from './components/RocketTransition';
8-
import UserProfileWidget from './components/UserProfileWidget';
98

109
function App() {
1110
const location = useLocation();
@@ -20,7 +19,6 @@ function App() {
2019
</Link>
2120
</div>
2221
)}
23-
{!isHomePage && <UserProfileWidget />}
2422

2523
<main className="main-content">
2624
<Routes>

src/context/AppContext.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface UserPreferences {
2020
interface AppContextType {
2121
preferences: UserPreferences | null;
2222
setPreferences: (prefs: UserPreferences) => void;
23+
clearPreferences: () => void;
2324
matches: AlienProfile[];
2425
addMatch: (alien: AlienProfile) => void;
2526
}
@@ -50,14 +51,21 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
5051
setPreferencesState(prefs);
5152
};
5253

54+
const clearPreferences = () => {
55+
setPreferencesState(null);
56+
setMatches([]);
57+
localStorage.removeItem('aligned_preferences');
58+
localStorage.removeItem('aligned_matches');
59+
};
60+
5361
const addMatch = (alien: AlienProfile) => {
5462
if (!matches.find(m => m.id === alien.id)) {
5563
setMatches([...matches, alien]);
5664
}
5765
};
5866

5967
return (
60-
<AppContext.Provider value={{ preferences, setPreferences, matches, addMatch }}>
68+
<AppContext.Provider value={{ preferences, setPreferences, clearPreferences, matches, addMatch }}>
6169
{children}
6270
</AppContext.Provider>
6371
);

src/pages/home/Home.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import { useEffect } from 'react';
12
import { Link } from 'react-router';
3+
import { useAppContext } from '../../context/AppContext';
24
import styles from "./Home.module.css";
35

46
function Home() {
7+
const { clearPreferences } = useAppContext();
8+
9+
// Reset all user data when returning to the home page
10+
useEffect(() => {
11+
clearPreferences();
12+
}, []);
13+
514
return (
615
<div className={styles.homeContainer}>
716
<img src={`${import.meta.env.BASE_URL}SSTRUK-logo.png?v=5`} alt="SSTRUK Logo" className={styles.logo} />

0 commit comments

Comments
 (0)