diff --git a/.gitignore b/.gitignore index 978f257..fff3377 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ lerna-debug.log* *.sln *.sw? -backend/.secrets +backend/.secrets.js diff --git a/backend/app.js b/backend/app.js index 258e018..d3caed7 100644 --- a/backend/app.js +++ b/backend/app.js @@ -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; diff --git a/frontend/resias/src/api/api.tsx b/frontend/resias/src/api/api.tsx index c12d087..d9da4cc 100644 --- a/frontend/resias/src/api/api.tsx +++ b/frontend/resias/src/api/api.tsx @@ -1 +1,17 @@ -import type { Sticky } from '../types/types'; \ No newline at end of file +import { useQuery } from '@tanstack/react-query'; +import type { Sticky } from '../types/types'; + +const fetchStickies = async (): Promise => { + 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({ + queryKey: ['stickies'], + queryFn: fetchStickies, + }); +}; diff --git a/frontend/resias/src/components/stickies.css b/frontend/resias/src/components/stickies.css new file mode 100644 index 0000000..20f30d6 --- /dev/null +++ b/frontend/resias/src/components/stickies.css @@ -0,0 +1,7 @@ +.stickies-grid { + display: flex; + flex-wrap: wrap; + gap: 16px; + justify-content: center; + padding: 24px; +} diff --git a/frontend/resias/src/components/stickies.tsx b/frontend/resias/src/components/stickies.tsx index 4e59106..5c7bed4 100644 --- a/frontend/resias/src/components/stickies.tsx +++ b/frontend/resias/src/components/stickies.tsx @@ -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
Loading...
; - if (error) return
Error: {error.message}
; + if (isLoading) return
Loading...
; + if (error) return
Error: {error.message}
; - return
{data?.map((sticky) =>
{sticky.text}
)}
; - }; + return ( +
+ {data?.map((sticky) => ( + + ))} +
+ ); +}; - export default Stickies; \ No newline at end of file +export default Stickies; diff --git a/frontend/resias/src/components/sticky.tsx b/frontend/resias/src/components/sticky.tsx index e69de29..8123e57 100644 --- a/frontend/resias/src/components/sticky.tsx +++ b/frontend/resias/src/components/sticky.tsx @@ -0,0 +1,43 @@ +import type { Sticky as StickyType } from '../types/types'; + +const COLOR_MAP: Record = { + 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 ( +
+ {sticky.text} +
+ ); +}; + +export default Sticky;