/* eslint-disable @typescript-eslint/no-explicit-any */ 'use client' import RoomCard from '@/components/RoomCard' import { CallApi } from '@/helper/api/ApiConnector' import Link from 'next/link' import React, { useState } from 'react' export default function Search() { const [details, setDetails] = useState<{ id?: number; image: any, title: string, room: string, color: string }>() const handleSave = async () => { console.log(await CallApi(`/room`, 'POST', { id: 0, ...details,image: details?.image })) } return (
setDetails((d: any) => { return { ...d, title: e.target.value } })} className='text-white w-full border-0 focus:p-2 transition-all focus:border-0' />
{ const file = e.target.files![0] if (file && file.type.startsWith('image/')) { const reader = new FileReader(); // Create a new FileReader instance // Set up the onload event for the reader reader.onload = function (e) { // e.target.result contains the image data as a Base64 encoded URL (data URL) console.log('Image Data URL:', e.target!.result); // You can now set the src of an image tag to this data URL to display it setDetails((d: any) => { return { ...d, image: e.target!.result } }) // imagePreview.src = e.target.result; // To get pixel data (ImageData object), you would use a canvas element // (See "Getting Pixel Data" below) }; // Read the image file as a Data URL reader.readAsDataURL(file); } else { // imagePreview.src = '#'; // Clear preview if not an image console.error('Please select a valid image file.'); } }} className='text-white' type='file' name='image' />
setDetails((d: any) => { return { ...d, color: e.target.value } })} type='color' name='color' />
{details && }
) }