Merge branch 'main' into a11y/focus-plugin-auth

This commit is contained in:
Kay Belardinelli 2025-04-04 09:21:18 -04:00 committed by GitHub
commit 1a8911d913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 300 additions and 73 deletions

View file

@ -55,8 +55,8 @@ export const URLIcon = memo(
onError={handleImageError}
loading="lazy"
decoding="async"
width={Number(containerStyle.width)}
height={Number(containerStyle.height)}
width={Number(containerStyle.width) || 20}
height={Number(containerStyle.height) || 20}
/>
</div>
);

View file

@ -11,6 +11,28 @@ const clearDraft = debounce((id?: string | null) => {
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${id ?? ''}`);
}, 2500);
const encodeBase64 = (plainText: string): string => {
try {
const textBytes = new TextEncoder().encode(plainText);
return btoa(String.fromCharCode(...textBytes));
} catch (e) {
return '';
}
};
const decodeBase64 = (base64String: string): string => {
try {
const bytes = atob(base64String);
const uint8Array = new Uint8Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
uint8Array[i] = bytes.charCodeAt(i);
}
return new TextDecoder().decode(uint8Array);
} catch (e) {
return '';
}
};
export const useAutoSave = ({
conversationId,
textAreaRef,
@ -30,28 +52,6 @@ export const useAutoSave = ({
const fileIds = useMemo(() => Array.from(files.keys()), [files]);
const { data: fileList } = useGetFiles<TFile[]>();
const encodeBase64 = (plainText: string): string => {
try {
const textBytes = new TextEncoder().encode(plainText);
return btoa(String.fromCharCode(...textBytes));
} catch (e) {
return '';
}
};
const decodeBase64 = (base64String: string): string => {
try {
const bytes = atob(base64String);
const uint8Array = new Uint8Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
uint8Array[i] = bytes.charCodeAt(i);
}
return new TextDecoder().decode(uint8Array);
} catch (e) {
return '';
}
};
const restoreFiles = useCallback(
(id: string) => {
const filesDraft = JSON.parse(
@ -126,16 +126,17 @@ export const useAutoSave = ({
return;
}
const handleInput = debounce(() => {
if (textAreaRef?.current && textAreaRef.current.value) {
const handleInput = debounce((e: React.ChangeEvent<HTMLTextAreaElement>) => {
const value = e.target.value;
if (value) {
localStorage.setItem(
`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`,
encodeBase64(textAreaRef.current.value),
encodeBase64(value),
);
} else {
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`);
}
}, 1000);
}, 750);
const textArea = textAreaRef?.current;
if (textArea) {

View file

@ -645,7 +645,7 @@ export default function useEventHandlers({
} else {
cancelHandler(data, submission);
}
} else if (response.status === 204) {
} else if (response.status === 204 || response.status === 200) {
const responseMessage = {
...submission.initialResponse,
};