Skip to content

Commit ab67080

Browse files
committed
add checkbox and localstorage functionality for enabling/disabling autofocus
1 parent ce857b1 commit ab67080

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/features/decoder/components/jwt-input.component.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CardToolbarComponent } from "@/features/common/components/card-toolbar/
1414
import { CardToolbarCopyButtonComponent } from "@/features/common/components/card-toolbar-buttons/card-toolbar-copy-button/card-toolbar-copy-button.component";
1515
import { CardToolbarClearButtonComponent } from "@/features/common/components/card-toolbar-buttons/card-toolbar-clear-button/card-toolbar-clear-button.component";
1616
import styles from "./jwt-input.module.scss";
17+
import { CheckboxComponent } from "@/features/common/components/checkbox/checkbox.component";
1718

1819
type JwtInputComponentProps = {
1920
languageCode: string;
@@ -24,14 +25,18 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
2425
languageCode,
2526
dictionary,
2627
}) => {
28+
const [autoFocusEnabled, setAutofocusEnabled] = useState(() => {
29+
const saved = localStorage.getItem("autofocus-enabled");
30+
return saved ? !!JSON.parse(saved) : false
31+
});
2732
const handleJwtChange$ = useDecoderStore((state) => state.handleJwtChange);
2833
const jwt$ = useDecoderStore((state) => state.jwt);
2934
const decodeErrors$ = useDecoderStore((state) => state.decodingErrors);
3035

3136
const decoderInputs$ = useDebuggerStore((state) => state.decoderInputs$);
3237

3338
const [token, setToken] = useState<string>(
34-
decoderInputs$.jwt || DEFAULT_JWT.token,
39+
decoderInputs$.jwt || DEFAULT_JWT.token
3540
);
3641

3742
const clearValue = async () => {
@@ -46,13 +51,23 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
4651
handleJwtChange$(cleanValue);
4752
};
4853

54+
const handleCheckboxChange = (selected: boolean) => {
55+
localStorage.setItem("autofocus-enabled", JSON.stringify(selected))
56+
setAutofocusEnabled(selected)
57+
}
58+
4959
useEffect(() => {
5060
setToken(jwt$);
5161
}, [jwt$]);
5262

5363
return (
5464
<>
55-
<span className={styles.headline}>{dictionary.headline}</span>
65+
<div style={{ display: "flex", justifyContent: "space-between" }}>
66+
<span className={styles.headline}>{dictionary.headline}</span>
67+
<CheckboxComponent isSelected={autoFocusEnabled} onChange={e => handleCheckboxChange(e)}>
68+
<span className={styles.checkbox__label}>Enable auto-focus</span>
69+
</CheckboxComponent>
70+
</div>
5671
<CardComponent
5772
id={dataTestidDictionary.decoder.jwtEditor.id}
5873
languageCode={languageCode}
@@ -84,7 +99,7 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
8499
),
85100
}}
86101
>
87-
<JwtEditorComponent token={token} handleJwtChange={handleJwtChange} />
102+
<JwtEditorComponent token={token} handleJwtChange={handleJwtChange} autoFocus={autoFocusEnabled}/>
88103
</CardComponent>
89104
</>
90105
);

0 commit comments

Comments
 (0)