Skip to content

Commit aa84f5b

Browse files
revert(web): remove all core /src changes, keep only test files
1 parent 2135c2b commit aa84f5b

6 files changed

Lines changed: 44 additions & 77 deletions

File tree

apps/web/src/components/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Link } from 'react-router-dom';
2-
import { useTheme } from '../lib/useTheme';
2+
import { useTheme } from '../lib/theme';
33
import './Navbar.css';
44

55
export default function Navbar() {

apps/web/src/lib/ThemeContext.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/web/src/lib/theme.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { useEffect, useState, type ReactNode } from 'react';
2-
import { ThemeContext } from './ThemeContext';
3-
import type { ThemeContextValue } from './ThemeContext';
1+
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
42

53
type Theme = 'light' | 'dark';
64

5+
interface ThemeContextValue {
6+
theme: Theme;
7+
toggleTheme: () => void;
8+
}
9+
10+
const ThemeContext = createContext<ThemeContextValue | null>(null);
11+
712
function getInitialTheme(): Theme {
813
if (typeof window === 'undefined') return 'dark';
914

@@ -28,11 +33,15 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
2833

2934
const toggleTheme = () => setTheme((t) => (t === 'dark' ? 'light' : 'dark'));
3035

31-
const value: ThemeContextValue = { theme, toggleTheme };
32-
3336
return (
34-
<ThemeContext.Provider value={value}>
37+
<ThemeContext.Provider value={{ theme, toggleTheme }}>
3538
{children}
3639
</ThemeContext.Provider>
3740
);
3841
}
42+
43+
export function useTheme(): ThemeContextValue {
44+
const ctx = useContext(ThemeContext);
45+
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
46+
return ctx;
47+
}

apps/web/src/lib/useTheme.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

apps/web/src/pages/CardPage.tsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,17 @@ export default function CardPage() {
2424

2525
useEffect(() => {
2626
if (!id) return;
27-
28-
let cancelled = false;
29-
30-
const fetchCard = async () => {
31-
try {
32-
const data = await apiFetch<PublicCard>(`/api/u/card/${id}`);
33-
if (!cancelled) {
34-
setCard(data);
35-
setError(null);
36-
}
37-
} catch {
38-
if (!cancelled) {
39-
setCard(null);
40-
setError('Card not found');
41-
}
42-
} finally {
43-
if (!cancelled) setLoading(false);
44-
}
45-
};
46-
47-
fetchCard();
48-
49-
return () => {
50-
cancelled = true;
51-
};
27+
setLoading(true);
28+
apiFetch<PublicCard>(`/api/u/card/${id}`)
29+
.then((data) => {
30+
setCard(data);
31+
setError(null);
32+
})
33+
.catch(() => {
34+
setCard(null);
35+
setError('Card not found');
36+
})
37+
.finally(() => setLoading(false));
5238
}, [id]);
5339

5440
// Update document title

apps/web/src/pages/ProfilePage.tsx

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,27 @@ export default function ProfilePage() {
1818
const [profile, setProfile] = useState<PublicProfile | null>(null);
1919
const [error, setError] = useState<string | null>(null);
2020
const [loading, setLoading] = useState(true);
21+
const [mounted, setMounted] = useState(false);
2122
const [copyMessage, setCopyMessage] = useState('');
2223
const [copyStatus, setCopyStatus] = useState<'success' | 'error'>('success');
2324

2425
useEffect(() => {
25-
if (!username) return;
26-
27-
let cancelled = false;
28-
29-
const fetchProfile = async () => {
30-
try {
31-
const data = await apiFetch<PublicProfile>(`/api/u/${username}?source=web`);
32-
if (!cancelled) {
33-
setProfile(data);
34-
setError(null);
35-
}
36-
} catch {
37-
if (!cancelled) {
38-
setProfile(null);
39-
setError('User not found');
40-
}
41-
} finally {
42-
if (!cancelled) setLoading(false);
43-
}
44-
};
26+
setMounted(true);
27+
}, []);
4528

46-
fetchProfile();
47-
48-
return () => {
49-
cancelled = true;
50-
};
29+
useEffect(() => {
30+
if (!username) return;
31+
setLoading(true);
32+
apiFetch<PublicProfile>(`/api/u/${username}?source=web`)
33+
.then((data) => {
34+
setProfile(data);
35+
setError(null);
36+
})
37+
.catch(() => {
38+
setProfile(null);
39+
setError('User not found');
40+
})
41+
.finally(() => setLoading(false));
5142
}, [username]);
5243

5344
async function copyProfileUrl() {
@@ -116,7 +107,7 @@ export default function ProfilePage() {
116107
className="bg-gradient"
117108
style={{ '--accent': profile.accentColor || '#6366f1' } as React.CSSProperties}
118109
/>
119-
<main className="profile-container loaded">
110+
<main className={`profile-container ${mounted ? 'loaded' : ''}`}>
120111
<div
121112
className="profile-card glass"
122113
style={{ '--accent': profile.accentColor } as React.CSSProperties}

0 commit comments

Comments
 (0)