This commit is contained in:
KS Jannette
2026-02-11 14:16:19 -05:00
parent bdc88f5d16
commit 14bd1add26
6 changed files with 85 additions and 13 deletions

2
.gitignore vendored
View File

@@ -21,4 +21,4 @@ lerna-debug.log*
*.sln
*.sw?
backend/.secrets
backend/.secrets.js

View File

@@ -7,6 +7,6 @@ const app = express();
app.use(cors());
app.use(express.json());
app.use('/api/notes', notesRoutes);
app.use('/v1/notes', notesRoutes);
export default app;

View File

@@ -1 +1,17 @@
import type { Sticky } from '../types/types';
import { useQuery } from '@tanstack/react-query';
import type { Sticky } from '../types/types';
const fetchStickies = async (): Promise<Sticky[]> => {
const response = await fetch('http://localhost:3001/v1/notes');
if (!response.ok) {
throw new Error('Failed to fetch stickies');
}
return response.json();
};
export const useGetStickies = () => {
return useQuery<Sticky[]>({
queryKey: ['stickies'],
queryFn: fetchStickies,
});
};

View File

@@ -0,0 +1,7 @@
.stickies-grid {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
padding: 24px;
}

View File

@@ -1,14 +1,20 @@
import { useState} from "react";
import { useGetStickies } from '../api/api';
import Sticky from './sticky';
import './stickies.css';
const Stickies = () => {
const isLoading = useState(false);
const error = useState(false);
let data: any = [];
const Stickies = () => {
const { data, isLoading, error } = useGetStickies();
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return <div>{data?.map((sticky) => <div key={sticky.id}>{sticky.text}</div>)}</div>;
};
return (
<div className="stickies-grid">
{data?.map((sticky) => (
<Sticky key={sticky.id} sticky={sticky} />
))}
</div>
);
};
export default Stickies;
export default Stickies;

View File

@@ -0,0 +1,43 @@
import type { Sticky as StickyType } from '../types/types';
const COLOR_MAP: Record<string, string> = {
yellow: '#fdfd96',
blue: '#a2d2ff',
green: '#b5ead7',
pink: '#ffb7ce',
purple: '#cdb4db',
orange: '#ffc09f',
};
type StickyProps = {
sticky: StickyType;
};
const Sticky = ({ sticky }: StickyProps) => {
const backgroundColor = COLOR_MAP[sticky.color] || '#fdfd96';
return (
<div
style={{
backgroundColor,
width: '180px',
minHeight: '180px',
padding: '16px',
borderRadius: '2px',
boxShadow: '2px 4px 8px rgba(0, 0, 0, 0.15)',
fontFamily: "'Patrick Hand', cursive, system-ui",
fontSize: '14px',
lineHeight: '1.4',
color: '#333',
display: 'flex',
alignItems: 'flex-start',
wordBreak: 'break-word',
transform: `rotate(${Math.random() * 4 - 2}deg)`,
}}
>
{sticky.text}
</div>
);
};
export default Sticky;