Skip to content

Commit f79ce4e

Browse files
committed
remove api usage
1 parent 9096f56 commit f79ce4e

File tree

12 files changed

+36
-226
lines changed

12 files changed

+36
-226
lines changed

src/app/api/cache/purge/schedule/route.ts

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

src/app/api/events/[slug]/route.ts

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

src/app/api/random-image/route.ts

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

src/app/api/sendToDiscord/route.js

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

src/app/events/components/event-sessions-list/event-popup.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import React from 'react';
2-
import { EventWithSessions } from '@/lib/events';
3-
import { useQuery } from '@tanstack/react-query';
1+
import React, { useMemo } from 'react';
2+
import { EventSession, EventWithSessions } from '@/lib/events';
43
import EventCard from '@/app/events/[slug]/components/event-card';
54
import { FloatingOverlay } from '@floating-ui/react';
65

76
export default function EventPopup({
87
selectedEventSlug,
8+
eventSessions,
99
onClose,
1010
}: {
1111
selectedEventSlug: string;
12+
eventSessions: EventSession[];
1213
onClose: () => void;
1314
}) {
14-
const query = useQuery<EventWithSessions>({
15-
queryKey: ['event', selectedEventSlug],
16-
queryFn: async () => {
17-
const response = await fetch('/api/events/' + selectedEventSlug);
18-
if (!response.ok) {
19-
throw new Error('Network response was not ok');
20-
}
21-
return response.json();
22-
},
23-
});
15+
const eventData = useMemo<EventWithSessions | null>(() => {
16+
const sessions = eventSessions.filter((s) => s.event.slug === selectedEventSlug);
17+
if (sessions.length === 0) return null;
18+
19+
const firstSession = sessions[0];
20+
return {
21+
...firstSession.event,
22+
sessions,
23+
};
24+
}, [selectedEventSlug, eventSessions]);
2425

2526
return (
2627
<>
@@ -33,12 +34,8 @@ export default function EventPopup({
3334
className="bg-white rounded-md max-w-full min-h-80 max-h-[calc(100vh-8rem)] overflow-y-auto cursor-default flex flex-col mx-2 mt-12"
3435
onClick={(e) => e.stopPropagation()}
3536
>
36-
{query.data ? (
37-
<EventCard event={query.data} onClose={onClose} />
38-
) : query.isLoading ? (
39-
<div className="w-3xl max-w-full p-6 text-lg flex justify-center items-center grow mb-8">
40-
Loading event...
41-
</div>
37+
{eventData ? (
38+
<EventCard event={eventData} onClose={onClose} />
4239
) : (
4340
<div className="w-3xl max-w-full p-6 text-lg flex flex-col gap-2 justify-center items-center grow mb-8">
4441
Could not find event

src/app/events/components/event-sessions-list/event-sessions-list.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export default function EventSessionsList({
116116
{selectedFilters.selectedEvent && (
117117
<EventPopup
118118
selectedEventSlug={selectedFilters.selectedEvent}
119+
eventSessions={eventSessions}
119120
onClose={() => setFilter({ selectedEvent: undefined })}
120121
/>
121122
)}

src/app/wpaint/components/Gallery.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
'use client';
22

33
import Image from 'next/image';
4-
import React, { useEffect, useState } from 'react';
4+
import React, { useMemo, useState } from 'react';
55

6-
const Gallery: React.FC = () => {
7-
const [imageFilenames, setImageFilenames] = useState<string[]>([]);
6+
const Gallery: React.FC<{ files: string[] }> = ({ files }) => {
87
const [selected, setSelected] = useState<number | null>(null);
98

109
const shuffleArray = (array: string[]) => {
11-
for (let i = array.length - 1; i > 0; i--) {
10+
const arr = [...array];
11+
for (let i = arr.length - 1; i > 0; i--) {
1212
const j = Math.floor(Math.random() * (i + 1));
13-
[array[i], array[j]] = [array[j], array[i]];
13+
[arr[i], arr[j]] = [arr[j], arr[i]];
1414
}
15-
return array;
15+
return arr;
1616
};
1717

18-
useEffect(() => {
19-
fetch('/api/gallery')
20-
.then((res) => res.json())
21-
.then((data) => {
22-
const shuffledFiles = shuffleArray(data.files);
23-
setImageFilenames(shuffledFiles);
24-
})
25-
.catch((err) => console.error('Failed to load images:', err));
26-
}, []);
18+
const imageFilenames = useMemo(() => shuffleArray(files), [files]);
2719

2820
return (
2921
<>
@@ -65,6 +57,6 @@ const Gallery: React.FC = () => {
6557
)}
6658
</>
6759
);
68-
};
60+
};;
6961

7062
export default Gallery;

src/app/wpaint/components/SubmissionModal.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, { useState } from 'react';
22
import Image from 'next/image';
3-
import { FiSend } from 'react-icons/fi';
4-
import ActionButton from './ActionButton';
5-
import { sendToDiscord } from '../lib/sendToDiscord';
63

74
interface SubmissionModalProps {
85
caption: string;
@@ -20,16 +17,7 @@ const SubmissionModal: React.FC<SubmissionModalProps> = ({
2017
const [showModal, setShowModal] = useState(false);
2118
const [previewDataUrl, setPreviewDataUrl] = useState<string | null>(null);
2219

23-
const handleSendClick = () => {
24-
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
25-
if (canvas) {
26-
setPreviewDataUrl(canvas.toDataURL('image/png'));
27-
}
28-
setShowModal(true);
29-
};
30-
3120
const handleConfirm = () => {
32-
sendToDiscord(caption, author);
3321
setShowModal(false);
3422
};
3523

src/app/wpaint/components/paint-app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const loadCanvasState = () => {
3838
}
3939
};
4040

41-
const PaintApp = () => {
41+
const PaintApp = ({ galleryFiles }: { galleryFiles: string[] }) => {
4242
const [brushSettings, setBrushSettings] = useState({
4343
color: '#4f1d75',
4444
size: 40,
@@ -239,7 +239,7 @@ const PaintApp = () => {
239239
/>
240240
</div>
241241
<h1 className="text-teal text-2xl font-semibold mb-2 mt-4">W-Gallery</h1>
242-
<Gallery />
242+
<Gallery files={galleryFiles} />
243243
</>
244244
);
245245
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { NextResponse } from 'next/server';
43

5-
export async function GET() {
4+
export async function getGalleryFiles(): Promise<string[]> {
65
const dir = path.join(process.cwd(), 'public/wpaint-gallery');
76
const files = fs.readdirSync(dir).filter((file) => file.endsWith('.jpg'));
8-
return NextResponse.json({ files });
7+
return files;
98
}

0 commit comments

Comments
 (0)