diff --git a/src/components/SchemaForm/components/Gif/GifFramePicker.tsx b/src/components/SchemaForm/components/Gif/GifFramePicker.tsx new file mode 100644 index 00000000..fca4b9ff --- /dev/null +++ b/src/components/SchemaForm/components/Gif/GifFramePicker.tsx @@ -0,0 +1,172 @@ +/* eslint-disable jsx-a11y/click-events-have-key-events */ +/* eslint-disable jsx-a11y/no-static-element-interactions */ +import React, { useState, FC, useCallback, useEffect } from 'react' +import Dialog from '@mui/material/Dialog' +import DialogContent from '@mui/material/DialogContent' +import DialogTitle from '@mui/material/DialogTitle' +import { + Box, + Button, + DialogActions, + Slider, + TextField, + Typography, + useTheme +} from '@mui/material' +import { Colorize } from '@mui/icons-material' +import useStore from '../../../../store/useStore' + +// interface Gif { +// name: string +// url: string +// } + +interface GifFramePickerProps { + onChange: (_url: string) => void + model: any +} + +const GifFramePicker: FC = ({ + onChange, + model +}: GifFramePickerProps) => { + const theme = useTheme() + const [open, setOpen] = useState(false) + // const [selectedGif, setSelectedGif] = useState(null) + // console.log(model.beat_frames) + const handleClickOpen = () => { + setOpen(true) + } + + const handleClose = () => { + setOpen(false) + } + + const [imageData, setImageData] = useState([]) + const getGifFrames = useStore((state) => state.getGifFrames) + const [currentFrame, setCurrentFrame] = useState(0) + const fetchImage = useCallback(async (ic: string) => { + const result = await getGifFrames(ic) + // console.log(result) + setImageData(result.frames) + }, []) + + useEffect(() => { + fetchImage(model.image_location) + }, []) + // useEffect(() => { + // if (open) + // fetch(baseUrl) + // .then((response) => response.text()) + // .then((data) => { + // const parser = new DOMParser() + // const doc = parser.parseFromString(data, 'text/html') + // const links = doc.querySelectorAll('pre a') + // const files = Array.from(links) + // .filter((link) => link.textContent?.endsWith('.gif')) + // .map((link: any) => ({ + // name: link.textContent?.replace('.gif', ''), + // url: baseUrl + link.href.split('/').pop() + // })) + // setGifs(files) + // }) + // }, [open]) + + return ( + <> + + + GIF Frame Picker + + {imageData && ( + <> + onChange(e.target.value)} + sx={{ margin: '20px 0', minWidth: '522px' }} + /> + + + Click on image to select/deselect + + +
{ + let output = '' + if ( + model.beat_frames + .split(' ') + .includes(currentFrame.toString()) + ) { + output = model.beat_frames + .split(' ') + .filter((b: string) => b !== currentFrame.toString()) + .join(' ') + } else { + output = model.beat_frames + .concat([` ${currentFrame.toString()}`]) + .split(' ') + .sort( + (a: string, b: string) => + parseInt(a, 10) - parseInt(b, 10) + ) + .join(' ') + } + onChange(output) + }} + /> + + ({ + value: b, + label: b.toString() + }))} + min={0} + max={imageData.length - 1 || 0} + onChange={(e, v) => { + setCurrentFrame(v as number) + // onChange(imageData[v as number]) + }} + /> + + + )} + + + + +
+ + ) +} + +export default GifFramePicker diff --git a/src/components/SchemaForm/components/Gif/GifPicker.tsx b/src/components/SchemaForm/components/Gif/GifPicker.tsx index e561e5da..fd6572fd 100644 --- a/src/components/SchemaForm/components/Gif/GifPicker.tsx +++ b/src/components/SchemaForm/components/Gif/GifPicker.tsx @@ -4,7 +4,7 @@ import DialogContent from '@mui/material/DialogContent' import DialogTitle from '@mui/material/DialogTitle' import TextField from '@mui/material/TextField' import { Button, DialogActions, useTheme } from '@mui/material' -import { Search } from '@mui/icons-material' +import fx from '../../../Icons/FX.svg' interface Gif { name: string @@ -85,8 +85,17 @@ const GifPicker: React.FC = ({ onChange }: any) => { return ( <> - GIF Picker diff --git a/src/components/SchemaForm/components/String/BladeSelect.tsx b/src/components/SchemaForm/components/String/BladeSelect.tsx index 8105fe4e..9ea26c47 100644 --- a/src/components/SchemaForm/components/String/BladeSelect.tsx +++ b/src/components/SchemaForm/components/String/BladeSelect.tsx @@ -13,7 +13,7 @@ import BladeFrame from '../BladeFrame' import { BladeSelectDefaultProps, BladeSelectProps } from './BladeSelect.props' import { Ledfx } from '../../../../api/ledfx' import GifPicker from '../Gif/GifPicker' -// import GifFrameSelector from '../Gif/GifFrameSelector' +import GifFramePicker from '../Gif/GifFramePicker' /** * ## String @@ -188,7 +188,7 @@ const BladeSelect = ({ }} style={textStyle as any} /> - {schema.id === 'gif_at' && ( + {schema.id === 'image_location' && ( { onChange(model_id, gif) @@ -196,17 +196,17 @@ const BladeSelect = ({ }} /> )} - {/* {schema.id === 'beat frames' && - model['gif_at'] && - model['gif_at'] !== '' && ( - { onChange(model_id, gif) inputRef.current.value = gif }} /> - )} */} + )} {model_id === 'auth_token' && type === 'nanoleaf' && ( ({ getImage: async (path_url: string) => await Ledfx('/api/get_image', 'POST', { path_url }), + getGifFrames: async (path_url: string) => await Ledfx('/api/get_gif_frames', 'POST', { + path_url + }), }) export default storeActions