added server

This commit is contained in:
2025-10-20 06:32:14 -04:00
parent df7c275929
commit f2cf309d97
43 changed files with 1520 additions and 1 deletions

View File

@@ -0,0 +1,81 @@
import {useState, useEffect} from 'react';
import type {Artwork} from '@/types';
const SAMPLE_ARTWORKS: Artwork[] = [
{
id: '1',
title: 'Dragon 1',
description: '',
imageUrl: '/gallery/ArtFixture_2.jpg?inline',
},
{
id: '2',
title: 'Dragon 2',
description: '',
imageUrl: '/gallery/ArtFixture_3.jpg?inline',
},
{
id: '3',
title: 'Dragon 3',
description: '',
imageUrl: '/gallery/ArtFixture_4.jpg?inline',
},
{
id: '4',
title: 'Abstract Emotions',
description: '',
imageUrl: '/gallery/ArtFixture_5.jpg?inline',
},
{
id: '5',
title: 'Humorous',
description: '',
imageUrl: '/gallery/ArtFixture_6.png?inline',
},
{
id: '6',
title: 'Rainbows',
description: '',
imageUrl: '/gallery/ArtFixture_7.jpg?inline',
}
];
export const useArtwork = () => {
const [artworks, setArtworks] = useState<Artwork[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Load from localStorage or use sample data
const stored = localStorage.getItem('artworks');
if (stored) {
setArtworks(JSON.parse(stored));
} else {
setArtworks(SAMPLE_ARTWORKS);
localStorage.setItem('artworks', JSON.stringify(SAMPLE_ARTWORKS));
}
setLoading(false);
}, []);
const addArtwork = (artwork: Omit<Artwork, 'id'>) => {
const newArtwork: Artwork = {
...artwork,
id: Date.now().toString()
};
const updated = [...artworks, newArtwork];
setArtworks(updated);
localStorage.setItem('artworks', JSON.stringify(updated));
};
const deleteArtwork = (id: string) => {
const updated = artworks.filter(art => art.id !== id);
setArtworks(updated);
localStorage.setItem('artworks', JSON.stringify(updated));
};
return {
artworks,
loading,
addArtwork,
deleteArtwork
};
};

View File

@@ -0,0 +1,43 @@
import {useState, useEffect} from 'react';
import type {User} from '@/types';
export const useAuth = () => {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Check if user is logged in (from localStorage)
const storedUser = localStorage.getItem('user');
if (storedUser) {
setUser(JSON.parse(storedUser));
}
setLoading(false);
}, []);
const login = (email: string, password: string) => {
// Simple authentication (in production, use a real backend)
if (email && password) {
const newUser: User = {
email,
isAuthenticated: true
};
localStorage.setItem('user', JSON.stringify(newUser));
setUser(newUser);
return true;
}
return false;
};
const logout = () => {
localStorage.removeItem('user');
setUser(null);
};
return {
user,
loading,
login,
logout,
isAuthenticated: !!user?.isAuthenticated
};
};