From 7bde1b066a68fca6202b3f42c1cb54aa85c13890 Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Thu, 16 Nov 2023 02:18:38 -0500 Subject: use image toggle --- src/client/views/PropertiesView.tsx | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/client/views/PropertiesView.tsx') diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index 86784d467..6c193f5a7 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -3,7 +3,7 @@ import { IconLookup } from '@fortawesome/fontawesome-svg-core'; import { faAnchor, faArrowRight, faWindowMaximize } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Checkbox, Tooltip } from '@material-ui/core'; -import { ColorPicker, Colors, EditableText, IconButton, NumberInput, Size, Slider, Type } from 'browndash-components'; +import { Button, ColorPicker, Colors, EditableText, IconButton, NumberInput, Size, Slider, Type } from 'browndash-components'; import { concat } from 'lodash'; import { action, computed, IReactionDisposer, observable, reaction, trace } from 'mobx'; import { observer } from 'mobx-react'; @@ -40,7 +40,7 @@ import { PropertiesSection } from './PropertiesSection'; import './PropertiesView.scss'; import { DefaultStyleProvider } from './StyleProvider'; import { FaFillDrip } from 'react-icons/fa'; -import { GeneratedResponse } from '../apis/gpt/customization'; +import { GeneratedResponse, generatePalette } from '../apis/gpt/customization'; import { ExtractColors } from './ExtractColors'; const _global = (window /* browser */ || global) /* node */ as any; @@ -95,9 +95,27 @@ export class PropertiesView extends React.Component { @observable openStyling: boolean = true; // GPT styling + public styleInput: any; @observable generatedStyles: GeneratedResponse[] = []; @observable inputDocs: Doc[] = []; @observable selectedStyle: number = -1; + @observable useImageData = false; + + @action + gptStyling = async () => { + this.generatedStyles = []; + this.selectedStyle = -1; + try { + const res = await generatePalette(this.styleInput, this.useImageData); + if (typeof res === 'string') { + console.log(res); + const resObj = JSON.parse(res) as GeneratedResponse[]; + this.setGeneratedStyles(resObj); + } + } catch (err) { + console.error(err); + } + }; @action setGeneratedStyles = (responses: GeneratedResponse[]) => (this.generatedStyles = responses); @@ -1190,14 +1208,25 @@ export class PropertiesView extends React.Component {
{this.generatedStyles.length > 0 ? this.generatedStyles.map((style, i) => ( -
this.styleCollection(i)}> +
this.styleCollection(i)}>
{ExtractColors.sortColors(style.documentsWithColors.map(doc => ExtractColors.hexToFinalColor(doc.color))).map(c => ( -
+
))}
)) : 'Generating styles...'} +
+
+ + (this.useImageData = e.target.checked))} /> +
+
); -- cgit v1.2.3-70-g09d2