Skip to content
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
1,411 changes: 1,371 additions & 40 deletions apps/web/package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite --host",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"test": "vitest run"
},
"dependencies": {
"react": "^19.2.6",
Expand All @@ -16,6 +17,9 @@
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@sveltejs/vite-plugin-svelte": "^7.1.2",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.3.1",
"@types/node": "^24.12.3",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
Expand All @@ -24,8 +28,11 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.6.0",
"jsdom": "^29.1.1",
"svelte": "^5.56.3",
"typescript": "~6.0.2",
"typescript-eslint": "^8.59.2",
"vite": "^8.0.12"
"vite": "^8.0.12",
"vitest": "^4.1.8"
}
}
}
2 changes: 1 addition & 1 deletion apps/web/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from 'react-router-dom';
import { useTheme } from '../lib/theme';
import { useTheme } from '../lib/useTheme';
import './Navbar.css';

export default function Navbar() {
Expand Down
8 changes: 2 additions & 6 deletions apps/web/src/lib/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
import { createContext, useEffect, useState, type ReactNode } from 'react';

type Theme = 'light' | 'dark';

Expand Down Expand Up @@ -40,8 +40,4 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
);
}

export function useTheme(): ThemeContextValue {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
return ctx;
}
export { ThemeContext };
8 changes: 8 additions & 0 deletions apps/web/src/lib/useTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useContext } from 'react';
import { ThemeContext } from './theme';

export function useTheme() {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
return ctx;
}
1 change: 1 addition & 0 deletions apps/web/src/pages/CardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function CardPage() {

useEffect(() => {
if (!id) return;
// eslint-disable-next-line react-hooks/set-state-in-effect
setLoading(true);
apiFetch<PublicCard>(`/api/u/card/${id}`)
.then((data) => {
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export default function ProfilePage() {
const [copyStatus, setCopyStatus] = useState<'success' | 'error'>('success');

useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
setMounted(true);
}, []);

useEffect(() => {
if (!username) return;
// eslint-disable-next-line react-hooks/set-state-in-effect
setLoading(true);
apiFetch<PublicProfile>(`/api/u/${username}?source=web`)
.then((data) => {
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/routes/u/[username]/$types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PageData = {
profile?: { displayName: string; avatarUrl: string };
error?: string;
};
Comment thread
Satvik-art-creator marked this conversation as resolved.
11 changes: 11 additions & 0 deletions apps/web/src/routes/u/[username]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
import type { PageData } from './types';
export let data: PageData;
</script>
Comment thread
Satvik-art-creator marked this conversation as resolved.

{#if data?.error}
<div>{data.error}</div>
{:else if data?.profile}
<div>{data.profile.displayName}</div>
<img src={data.profile.avatarUrl} alt="avatar" />
{/if}
32 changes: 32 additions & 0 deletions apps/web/src/routes/u/[username]/+page.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import { render, screen } from '@testing-library/svelte';
import { describe, it, expect } from 'vitest';
import Page from './+page.svelte';

describe('Profile Page', () => {
it('renders profile data', () => {
// mock the loader data
const data = {
profile: {
displayName: 'John Doe',
avatarUrl: 'https://example.com/avatar.png'
}
};

render(Page, { props: { data } });

expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.getByAltText('avatar')).toHaveAttribute('src', 'https://example.com/avatar.png');
});

it('displays User Not Found message on loader error', () => {
// mock loader error
const data = {
error: 'User Not Found'
};

render(Page, { props: { data } });

expect(screen.getByText('User Not Found')).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions apps/web/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target": "es2023",
"lib": ["ES2023", "DOM"],
"module": "esnext",
"types": ["vite/client"],
"types": ["vite/client", "@testing-library/jest-dom"],
"skipLibCheck": true,

/* Bundler mode */
Expand All @@ -21,5 +21,5 @@
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src", "vitest-setup.ts"]
}
1 change: 1 addition & 0 deletions apps/web/vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest';
15 changes: 15 additions & 0 deletions apps/web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vitest/config';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
plugins: [svelte()],
test: {
environment: 'jsdom',
setupFiles: ['./vitest-setup.ts'],
include: ['src/**/*.test.ts'],
globals: true,
},
resolve: {
conditions: ['browser', 'svelte'],
},
Comment thread
Satvik-art-creator marked this conversation as resolved.
});