From 915e14ddabf8f49c7c8cd293f5b9f3222879523d Mon Sep 17 00:00:00 2001 From: sadan <117494111+sadan4@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:53:04 -0400 Subject: [PATCH] add things - add size slider - add preview when setting --- src/plugins/customFolderIcons/index.tsx | 74 ++++++++++++++++++++----- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx index 90848827b..5f19d0dd3 100644 --- a/src/plugins/customFolderIcons/index.tsx +++ b/src/plugins/customFolderIcons/index.tsx @@ -9,10 +9,11 @@ import { showNotification } from "@api/Notifications"; import { Devs } from "@utils/constants"; import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import definePlugin from "@utils/types"; -import { Button, Menu, TextInput } from "@webpack/common"; +import { Button, Menu, Slider, TextInput, useState } from "@webpack/common"; const DATA_STORE_NAME = "CFI_DATA"; interface folderIcon{ url: string, + size: number, } interface folderStoredData { [key: string]: folderIcon | undefined @@ -54,12 +55,21 @@ export default definePlugin({ }, replace(props: any){ if(folderData && folderData[props.folderNode.id]){ + const data = folderData[props.folderNode.id]; return ( - + > + + ); } } @@ -68,17 +78,18 @@ export default definePlugin({ * @param rgbVal RGB value * @param alpha alpha bewteen zero and 1 */ -const int2rgba = (rgbVal: number, alpha: number = 1)=>{ +function int2rgba(rgbVal: number, alpha: number = 1) { const b = rgbVal & 0xFF, g = (rgbVal & 0xFF00) >>> 8, r = (rgbVal & 0xFF0000) >>> 16; - return `rgba(${[r,g,b].join(",")},${alpha})`; -}; -const setFolderUrl = async (props: folderProp, url: string) => { + return `rgba(${[r, g, b].join(",")},${alpha})`; +} +async function setFolderUrl(props: folderProp, url: string, size: number) { DataStore.get(DATA_STORE_NAME).then(data => { data = data ?? {} as folderStoredData; data[props.folderId] = { url: url, + size: size }; DataStore.set(DATA_STORE_NAME, data).then(() => { folderData = data; }).catch(e => { handleUpdateError(e); @@ -88,25 +99,60 @@ const setFolderUrl = async (props: folderProp, url: string) => { .catch(e => { handleUpdateError(e); }); -}; - +} +function RenderPreview({ folderProps, url, size }: {folderProps: folderProp, url: string, size: number}){ + if (!url) return null; + return( +
+ +
+ ); +} function ImageModal(folderProps: folderProp){ - let data = ""; + const [data, setData]= useState(""); + const [size, setSize] = useState(100); return( <> -
{ - data = val; + setData(val); }} placeholder="https://example.com/image.png" > + + {data && <> +
Change the size of the folder icon
+ { + setSize(v); + }} + maxValue={200} + minValue={25} + markers={Array.apply(0, Array(176)).map((v, i) => i+25)} + stickToMarkers = {true} + keyboardStep={1} + renderMarker={() => null} + /> + }