Skip to content

Commit 21ab171

Browse files
committed
feat: Persist customization options across page refreshes
1 parent c978540 commit 21ab171

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/app/generator/repo-tree-generator.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,20 @@ export default function RepoProjectStructure() {
7676
const inputRef = useRef<HTMLInputElement>(null);
7777
const treeRef = useRef<HTMLDivElement>(null);
7878

79-
const [customizationOptions, setCustomizationOptions] =
80-
useState<TreeCustomizationOptions>({
81-
asciiStyle: 'basic',
82-
useIcons: false,
83-
showLineNumbers: false,
84-
});
79+
const [customizationOptions, setCustomizationOptions] = useState<TreeCustomizationOptions>(() => {
80+
const savedOptions = localStorage.getItem('customizationOptions');
81+
return savedOptions
82+
? JSON.parse(savedOptions)
83+
: {
84+
asciiStyle: 'basic',
85+
useIcons: false,
86+
showLineNumbers: false,
87+
};
88+
});
89+
90+
useEffect(() => {
91+
localStorage.setItem('customizationOptions', JSON.stringify(customizationOptions));
92+
}, [customizationOptions]);
8593

8694
const handleUrlChange = useCallback(
8795
(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -258,14 +266,13 @@ export default function RepoProjectStructure() {
258266
saveAs(new Blob([content], { type: mimeType }), fileName);
259267
}, [downloadFormat, customizedStructure, filteredStructureMap]);
260268

261-
const handleCustomizationChange = (
262-
newOptions: Partial<TreeCustomizationOptions>,
263-
) => {
264-
setCustomizationOptions((prevOptions: TreeCustomizationOptions) => ({
265-
...prevOptions,
266-
...newOptions,
267-
}));
268-
};
269+
const handleCustomizationChange = useCallback((newOptions: Partial<TreeCustomizationOptions>) => {
270+
setCustomizationOptions((prevOptions) => {
271+
const updatedOptions = { ...prevOptions, ...newOptions };
272+
localStorage.setItem('customizationOptions', JSON.stringify(updatedOptions));
273+
return updatedOptions;
274+
});
275+
}, []);
269276

270277
const noStructureMessage = `No structure generated yet. Enter a ${repoType === 'github' ? 'GitHub' : 'GitLab'} URL and click Generate.`;
271278
const noResultsMessage = useCallback(

0 commit comments

Comments
 (0)