Skip to content

Commit cba4817

Browse files
refactor(components): add prefix to localStorage key
1 parent 5d91a36 commit cba4817

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

specs/002-toggle-diff-options/data-model.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The granularity of comparison. A string union type with three possible values.
1818
- `'lines'` — line-level diff (`diffLines`)
1919

2020
**Default**: `'words'` (preserves current behavior)
21-
**Persistence**: localStorage key `'diffMethod'`
21+
**Persistence**: localStorage key `'diff.diffMethod'`
2222

2323
## Modified Entities
2424

@@ -30,7 +30,7 @@ The `DiffResult` interface (`segments` + `hasChanges`) remains unchanged. The di
3030

3131
The `ViewMode` type (`'unified' | 'side-by-side'`) remains unchanged. It gains localStorage persistence via the same `useLocalStorage` hook.
3232

33-
**Persistence**: localStorage key `'viewMode'`
33+
**Persistence**: localStorage key `'diff.viewMode'`
3434

3535
## Hooks
3636

specs/002-toggle-diff-options/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
- [x] T008 [P] [US1] Create `DiffMethodToggleProps` interface in src/components/DiffMethodToggle/DiffMethodToggle.types.ts
5959
- [x] T009 [P] [US1] Create barrel export in src/components/DiffMethodToggle/index.ts
6060
- [x] T010 [US1] Implement `DiffMethodToggle` component with 3-button segmented group (Characters | Words | Lines), `role="group"`, `aria-label`, active/inactive Tailwind styling per research.md in src/components/DiffMethodToggle/DiffMethodToggle.tsx
61-
- [x] T011 [US1] Update `App` component: add `diffMethod` state via `useLocalStorage('diffMethod', 'words')`, migrate `viewMode` to `useLocalStorage('viewMode', 'unified')`, pass `diffMethod` to `useDiff` and `DiffMethodToggle`, place `DiffMethodToggle` on left side of diff header in src/components/App/App.tsx
61+
- [x] T011 [US1] Update `App` component: add `diffMethod` state via `useLocalStorage('diff.diffMethod', 'words')`, migrate `viewMode` to `useLocalStorage('diff.viewMode', 'unified')`, pass `diffMethod` to `useDiff` and `DiffMethodToggle`, place `DiffMethodToggle` on left side of diff header in src/components/App/App.tsx
6262

6363
**Checkpoint**: User Story 1 is fully functional — diff method toggle works, selections persist to localStorage, all tests pass.
6464

src/components/App/App.test.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ describe('App component', () => {
371371

372372
await user.click(screen.getByRole('button', { name: 'Lines' }));
373373

374-
expect(localStorage.getItem('diffMethod')).toBe(JSON.stringify('lines'));
374+
expect(localStorage.getItem('diff.diffMethod')).toBe(
375+
JSON.stringify('lines'),
376+
);
375377
});
376378

377379
it('restores diff method from localStorage on mount', async () => {
378-
localStorage.setItem('diffMethod', JSON.stringify('characters'));
380+
localStorage.setItem('diff.diffMethod', JSON.stringify('characters'));
379381

380382
const user = userEvent.setup();
381383
render(<App />);
@@ -405,15 +407,15 @@ describe('App component', () => {
405407

406408
await user.click(screen.getByRole('button', { name: /side-by-side/i }));
407409

408-
expect(localStorage.getItem('viewMode')).toBe(
410+
expect(localStorage.getItem('diff.viewMode')).toBe(
409411
JSON.stringify('side-by-side'),
410412
);
411413
});
412414

413415
it('restores view mode from localStorage on mount', async () => {
414416
const { mockMatchMedia } = createMockMatchMedia(true);
415417
window.matchMedia = mockMatchMedia;
416-
localStorage.setItem('viewMode', JSON.stringify('side-by-side'));
418+
localStorage.setItem('diff.viewMode', JSON.stringify('side-by-side'));
417419

418420
const user = userEvent.setup();
419421
const { container } = render(<App />);
@@ -550,11 +552,13 @@ describe('App component', () => {
550552

551553
await user.click(screen.getByRole('button', { name: 'Lines' }));
552554

553-
expect(localStorage.getItem('diffMethod')).toBe(JSON.stringify('lines'));
555+
expect(localStorage.getItem('diff.diffMethod')).toBe(
556+
JSON.stringify('lines'),
557+
);
554558
});
555559

556560
it('restores diff method from localStorage on mount', async () => {
557-
localStorage.setItem('diffMethod', JSON.stringify('characters'));
561+
localStorage.setItem('diff.diffMethod', JSON.stringify('characters'));
558562

559563
const user = userEvent.setup();
560564
render(<App />);
@@ -581,13 +585,13 @@ describe('App component', () => {
581585

582586
await user.click(screen.getByRole('button', { name: /side-by-side/i }));
583587

584-
expect(localStorage.getItem('viewMode')).toBe(
588+
expect(localStorage.getItem('diff.viewMode')).toBe(
585589
JSON.stringify('side-by-side'),
586590
);
587591
});
588592

589593
it('restores view mode from localStorage on mount', async () => {
590-
localStorage.setItem('viewMode', JSON.stringify('side-by-side'));
594+
localStorage.setItem('diff.viewMode', JSON.stringify('side-by-side'));
591595

592596
window.matchMedia = vi.fn().mockReturnValue({
593597
matches: true,

src/components/App/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export default function App() {
1212
const [originalText, setOriginalText] = useState('');
1313
const [modifiedText, setModifiedText] = useState('');
1414
const [viewMode, setViewMode] = useLocalStorage<ViewMode>(
15-
'viewMode',
15+
'diff.viewMode',
1616
'unified',
1717
);
1818
const [diffMethod, setDiffMethod] = useLocalStorage<DiffMethod>(
19-
'diffMethod',
19+
'diff.diffMethod',
2020
'words',
2121
);
2222

0 commit comments

Comments
 (0)