Skip to content

Commit ce1cf74

Browse files
committed
Enable copy button for AI responses
Also wire that same copy text through to the feedback dialog.
1 parent dfb7381 commit ce1cf74

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/AiResponse.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from './Chat';
2121
import { StylesContext } from './Styles';
2222
import { FeedbackContext } from './Feedback';
23+
import Clipboard from '@react-native-clipboard/clipboard';
2324

2425
type AiImageResponseProps = {
2526
imageUrl?: string;
@@ -116,16 +117,17 @@ function AiTextResponse({text}: AiTextResponseProps): JSX.Element {
116117

117118
type AiSectionProps = PropsWithChildren<{
118119
isLoading?: boolean;
120+
copyValue?: string;
119121
contentShownOnHover?: JSX.Element;
120122
}>;
121-
function AiSection({children, isLoading, contentShownOnHover}: AiSectionProps): JSX.Element {
123+
function AiSection({children, isLoading, copyValue, contentShownOnHover}: AiSectionProps): JSX.Element {
122124
const feedbackContext = React.useContext(FeedbackContext);
123125
const styles = React.useContext(StylesContext);
124126
const [hovering, setHovering] = React.useState(false);
125127

126128
const showFeedbackPopup = (positive: boolean) => {
127129
if (feedbackContext) {
128-
feedbackContext.showFeedback(positive);
130+
feedbackContext.showFeedback(positive, copyValue);
129131
}
130132
}
131133

@@ -137,7 +139,7 @@ function AiSection({children, isLoading, contentShownOnHover}: AiSectionProps):
137139
<View style={{flexDirection: 'row'}}>
138140
<Text style={[styles.sectionTitle, {flexGrow: 1}]}>AI</Text>
139141
{hovering && contentShownOnHover}
140-
{hovering && <HoverButton content="📋" tooltip="Copy to clipboard" onPress={() => console.log("Copy: Not yet implemented")}/>}
142+
{hovering && copyValue && <HoverButton content="📋" tooltip="Copy to clipboard" onPress={() => Clipboard.setString(copyValue)}/>}
141143
<HoverButton content="👍" tooltip="Give positive feedback" onPress={() => { showFeedbackPopup(true); }}/>
142144
<HoverButton content="👎" tooltip="Give negative feedback" onPress={() => { showFeedbackPopup(false); }}/>
143145
</View>
@@ -158,7 +160,7 @@ type AiSectionContentProps = {
158160
function AiSectionContent({id, content}: AiSectionContentProps): JSX.Element {
159161
const chatHistory = React.useContext(ChatHistoryContext);
160162
return (
161-
<AiSection>
163+
<AiSection copyValue={content.text}>
162164
{(() => {
163165
switch (content.contentType) {
164166
case ChatContent.Error:

src/Chat.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ function ChatEntry({submit, defaultText, clearConversation}: ChatEntryProps): JS
8282
onSubmitEditing={submitValue}
8383
value={defaultText ?? value}/>
8484
<Button
85-
style={{flexShrink: 0}}
8685
title="Submit"
8786
onPress={submitValue}/>
8887
<Button
89-
style={{flexShrink: 0}}
9088
title="💣"
9189
onPress={clearConversation}/>
9290
</View>
@@ -104,6 +102,7 @@ function Chat({entries, humanText, onPrompt, clearConversation}: ChatProps): JSX
104102
const styles = React.useContext(StylesContext);
105103
const chatHistory = React.useContext(ChatHistoryContext);
106104
const [showFeedbackPopup, setShowFeedbackPopup] = React.useState(false);
105+
const [feedbackTargetResponse, setFeedbackTargetResponse] = React.useState<string | undefined>(undefined);
107106
const [showSettingsPopup, setShowSettingsPopup] = React.useState(false);
108107
const [showAboutPopup, setShowAboutPopup] = React.useState(false);
109108
const [feedbackIsPositive, setFeedbackIsPositive] = React.useState(false);
@@ -112,9 +111,10 @@ function Chat({entries, humanText, onPrompt, clearConversation}: ChatProps): JSX
112111
let showingAnyPopups = (showFeedbackPopup || showSettingsPopup || showAboutPopup);
113112

114113
const feedbackContext = {
115-
showFeedback: (positive: boolean) => {
114+
showFeedback: (positive: boolean, response?: string) => {
116115
setFeedbackIsPositive(positive);
117116
setShowFeedbackPopup(true);
117+
setFeedbackTargetResponse(response);
118118
}
119119
}
120120

@@ -195,6 +195,7 @@ function Chat({entries, humanText, onPrompt, clearConversation}: ChatProps): JSX
195195
<FeedbackPopup
196196
show={showFeedbackPopup}
197197
isPositive={feedbackIsPositive}
198+
response={feedbackTargetResponse}
198199
close={() => setShowFeedbackPopup(false)}/>
199200
<SettingsPopup
200201
show={showSettingsPopup}

src/Feedback.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import { Popup } from 'react-native-windows';
1010
import { StylesContext } from './Styles';
1111

1212
const FeedbackContext = React.createContext<{
13-
showFeedback : (positive: boolean) => void;
13+
showFeedback : (positive: boolean, response?: string) => void;
1414
}>({showFeedback: () => {}});
1515

1616
type FeedbackPopupProps = {
1717
show: boolean;
1818
close: () => void;
1919
isPositive: boolean;
20+
response?: string;
2021
}
21-
function FeedbackPopup({show, close, isPositive}: FeedbackPopupProps): JSX.Element {
22+
function FeedbackPopup({show, close, isPositive, response}: FeedbackPopupProps): JSX.Element {
2223
const styles = React.useContext(StylesContext);
2324
const [feedbackText, setFeedbackText] = React.useState("");
2425

@@ -61,6 +62,7 @@ function FeedbackPopup({show, close, isPositive}: FeedbackPopupProps): JSX.Eleme
6162
title="Submit feedback"
6263
onPress={() => {
6364
console.log(isPositive ? "like" : "dislike");
65+
console.log(response);
6466
console.log(feedbackText);
6567
close();
6668
}}/>

0 commit comments

Comments
 (0)