|
3 | 3 | import { useState, useRef, useEffect } from 'react'; |
4 | 4 | import { useRouter, useSearchParams } from 'next/navigation'; |
5 | 5 | import { toast } from 'sonner'; |
| 6 | +import { compressImageForSpotify } from '@/lib/image-compress'; |
6 | 7 | import { ImagePlus, Pencil, Plus, Search, Download, ChevronRight, ChevronLeft } from 'lucide-react'; |
7 | 8 | import { m } from 'motion/react'; |
8 | 9 | import { springs, STAGGER_DELAY } from '@/lib/motion'; |
@@ -277,16 +278,16 @@ export default function DashboardClient({ |
277 | 278 | setIsCreating(false); |
278 | 279 | } |
279 | 280 |
|
280 | | - function handleCreateImageSelect(e: React.ChangeEvent<HTMLInputElement>) { |
| 281 | + async function handleCreateImageSelect(e: React.ChangeEvent<HTMLInputElement>) { |
281 | 282 | const file = e.target.files?.[0]; |
282 | 283 | if (!file) return; |
283 | | - if (file.size > 256 * 1024) { |
284 | | - toast.error('Image must be under 256KB for Spotify'); |
285 | | - return; |
| 284 | + |
| 285 | + try { |
| 286 | + const dataUrl = await compressImageForSpotify(file); |
| 287 | + setCreateImagePreview(dataUrl); |
| 288 | + } catch { |
| 289 | + toast.error('Image could not be compressed under 256KB'); |
286 | 290 | } |
287 | | - const reader = new FileReader(); |
288 | | - reader.onload = (ev) => setCreateImagePreview(ev.target?.result as string); |
289 | | - reader.readAsDataURL(file); |
290 | 291 | } |
291 | 292 |
|
292 | 293 | function resetImportState() { |
@@ -589,7 +590,7 @@ export default function DashboardClient({ |
589 | 590 | <input |
590 | 591 | ref={createFileInputRef} |
591 | 592 | type="file" |
592 | | - accept="image/jpeg,image/png" |
| 593 | + accept="image/jpeg,image/png,image/webp" |
593 | 594 | onChange={handleCreateImageSelect} |
594 | 595 | className="hidden" |
595 | 596 | /> |
|
0 commit comments