From 05bc8d0fe9fc5f455260a63a7c9983455567c5de Mon Sep 17 00:00:00 2001 From: AllierByron <99301366+AllierByron@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:31:08 -0600 Subject: [PATCH] Buttons affected for visual aid added (#21) * visual indicative for active mode added (colored buttons), copy button added * copy on clipboard function extracted from onClick prop --------- Co-authored-by: Byron <212220367@soy.utj.edu.mx> --- src/app/components/Model.tsx | 58 +++++++++++++++++++++++----------- src/app/components/Result.tsx | 24 ++++++++++++-- src/app/components/ToolBar.tsx | 15 +++++---- 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/src/app/components/Model.tsx b/src/app/components/Model.tsx index 19bbf32..4c7a46c 100644 --- a/src/app/components/Model.tsx +++ b/src/app/components/Model.tsx @@ -1,4 +1,5 @@ -import React from 'react'; +/* eslint-disable @typescript-eslint/no-floating-promises */ +import React, { useState } from 'react'; import Editor from 'react-simple-code-editor'; import { highlight, languages } from 'prismjs'; import 'prismjs/components/prism-typescript'; @@ -13,23 +14,44 @@ interface ModelTypes { } // model are the inputs from the user, these are part of the prompt -export const Model = ({ userInput, updateUserInput, disabled }: ModelTypes) => ( -
-

Model

-
- highlight(userInputWritten, languages.tsx, 'tsx')} - onValueChange={(userInputWritten) => updateUserInput(userInputWritten)} - className='min-h-full' - preClassName='!break-all ' - textareaClassName='!break-all ' - padding={7} - disabled={disabled} - placeholder='Input some code...' - /> +export const Model = ({ userInput, updateUserInput, disabled }: ModelTypes) => { + const [copyText, onCopyText] = useState('Copy to clipboard'); + + const onCopyClick = () => { + navigator.clipboard.writeText(userInput); + onCopyText('Copied!'); + setTimeout(() => { + onCopyText('Copy to clipboard'); + }, 2000); + }; + + return ( +
+
+

Model

+ +
+
+ highlight(userInputWritten, languages.tsx, 'tsx')} + onValueChange={(userInputWritten) => updateUserInput(userInputWritten)} + className='min-h-full' + preClassName='!break-all ' + textareaClassName='!break-all ' + padding={7} + disabled={disabled} + placeholder='Input some code...' + /> +
-
-); + ); +}; export default Model; diff --git a/src/app/components/Result.tsx b/src/app/components/Result.tsx index 6d977b5..de0ce60 100644 --- a/src/app/components/Result.tsx +++ b/src/app/components/Result.tsx @@ -1,4 +1,5 @@ -import { useEffect } from 'react'; +/* eslint-disable @typescript-eslint/no-floating-promises */ +import { useEffect, useState } from 'react'; import Editor from 'react-simple-code-editor'; import { highlight, languages } from 'prismjs'; import 'prismjs/components/prism-typescript'; @@ -17,6 +18,8 @@ interface ResultTypes { // results are GPT responses exemplified by the user export const Result = ({ data, userResults, updateUserResults, disabled, isLoading, modeUp }: ResultTypes) => { + const [copyText, onCopyText] = useState('Copy to clipboard'); + useEffect(() => { if (typeof data === 'string') { updateUserResults(data); @@ -27,9 +30,26 @@ export const Result = ({ data, userResults, updateUserResults, disabled, isLoadi const placeHolderText = modeUp ? 'Field deactivated, input code in model to review it' : 'Input a result...'; + const onCopyClick = () => { + navigator.clipboard.writeText(userResults); + onCopyText('Copied!'); + setTimeout(() => { + onCopyText('Copy to clipboard'); + }, 2000); + }; + return (
-

Result

+
+

Result

+ +
{ if (userInput.trim() !== '' && userResults.trim() !== '') { updateUserInputArr({ input: userInput, result: userResults }); @@ -104,7 +101,9 @@ export const ToolBar = ({ isLoading, send, changeModeUp, modeUp }: toolBarInter)

Input mode