77ea27f5f5
Co-authored-by: Nahiyan Khan <nahiyan@squareup.com> Co-authored-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: Lily Delalande <119957291+lily-de@users.noreply.github.com> Co-authored-by: Spence <spencrmartin@gmail.com> Co-authored-by: spencrmartin <spencermartin@squareup.com> Co-authored-by: Judson Stephenson <Jud@users.noreply.github.com> Co-authored-by: Max Novich <mnovich@squareup.com> Co-authored-by: Best Codes <106822363+The-Best-Codes@users.noreply.github.com> Co-authored-by: caroline-a-mckenzie <cmckenzie@squareup.com> Co-authored-by: Michael Neale <michael.neale@gmail.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { all_response_styles, ResponseStyleSelectionItem } from './ResponseStyleSelectionItem';
|
|
|
|
export const ResponseStylesSection = () => {
|
|
const [currentStyle, setCurrentStyle] = useState('concise');
|
|
|
|
useEffect(() => {
|
|
const savedStyle = localStorage.getItem('response_style');
|
|
if (savedStyle) {
|
|
try {
|
|
setCurrentStyle(savedStyle);
|
|
} catch (error) {
|
|
console.error('Error parsing response style:', error);
|
|
}
|
|
} else {
|
|
// Set default to concise for new users
|
|
localStorage.setItem('response_style', 'concise');
|
|
setCurrentStyle('concise');
|
|
}
|
|
}, []);
|
|
|
|
const handleStyleChange = async (newStyle: string) => {
|
|
setCurrentStyle(newStyle);
|
|
localStorage.setItem('response_style', newStyle);
|
|
|
|
// Dispatch custom event to notify other components of the change
|
|
window.dispatchEvent(new CustomEvent('responseStyleChanged'));
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-1">
|
|
{all_response_styles.map((style) => (
|
|
<ResponseStyleSelectionItem
|
|
key={style.key}
|
|
style={style}
|
|
currentStyle={currentStyle}
|
|
showDescription={true}
|
|
handleStyleChange={handleStyleChange}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|