Skip to content

Commit 450a4ac

Browse files
committed
refactor mouse-form to use form helper utility
1 parent 32b2546 commit 450a4ac

1 file changed

Lines changed: 24 additions & 37 deletions

File tree

src/components/forms/mouse-form/mouse-form.component.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Component, computed, effect, inject } from '@angular/core';
1+
import { Component, computed, inject } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { FormsModule } from '@angular/forms';
4-
import { ConfigStoreService } from '../../../services/config-store.service';
54
import { KittyMouseConfig } from '../../../models/kitty-types';
65
import { NumberInputComponent } from '../../shared/number-input/number-input.component';
76
import { ColorInputComponent } from '../../shared/color-input/color-input.component';
7+
import { createFormHelper } from '../../../utils/form-helpers';
88

99
@Component({
1010
selector: 'app-mouse-form',
@@ -24,8 +24,8 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
2424
<span class="text-kitty-text-dim text-xs ml-2">Seconds idle before cursor hides (0 = never, -1 = hide on keypress)</span>
2525
</label>
2626
<app-number-input
27-
[(ngModel)]="mouse.mouse_hide_wait"
28-
(ngModelChange)="updateMouse()"
27+
[(ngModel)]="mouse().mouse_hide_wait"
28+
(ngModelChange)="helper.updateField('mouse_hide_wait', $event)"
2929
[min]="-1"
3030
[step]="0.5"
3131
/>
@@ -37,8 +37,8 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
3737
<span class="text-kitty-text-dim text-xs ml-2">Auto-copy selected text to clipboard</span>
3838
</label>
3939
<select
40-
[(ngModel)]="mouse.copy_on_select"
41-
(ngModelChange)="updateMouse()"
40+
[(ngModel)]="mouse().copy_on_select"
41+
(ngModelChange)="helper.updateField('copy_on_select', $event)"
4242
class="w-full px-4 py-2 bg-kitty-bg border border-kitty-border rounded-lg text-kitty-text focus:outline-none focus:ring-2 focus:ring-kitty-primary"
4343
>
4444
<option value="no">Disabled</option>
@@ -53,8 +53,8 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
5353
<label class="flex items-center gap-3 cursor-pointer">
5454
<input
5555
type="checkbox"
56-
[(ngModel)]="mouse.detect_urls"
57-
(ngModelChange)="updateMouse()"
56+
[(ngModel)]="mouse().detect_urls"
57+
(ngModelChange)="helper.updateField('detect_urls', $event)"
5858
class="w-5 h-5 rounded flex-shrink-0"
5959
/>
6060
<div>
@@ -68,8 +68,8 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
6868
<label class="flex items-center gap-3 cursor-pointer">
6969
<input
7070
type="checkbox"
71-
[(ngModel)]="mouse.focus_follows_mouse"
72-
(ngModelChange)="updateMouse()"
71+
[(ngModel)]="mouse().focus_follows_mouse"
72+
(ngModelChange)="helper.updateField('focus_follows_mouse', $event)"
7373
class="w-5 h-5 rounded flex-shrink-0"
7474
/>
7575
<div>
@@ -81,7 +81,7 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
8181
</div>
8282
</div>
8383
84-
@if (advancedMode()) {
84+
@if (helper.advancedMode()) {
8585
<div class="bg-kitty-surface rounded-lg p-6 border border-kitty-border">
8686
<h3 class="text-lg font-semibold text-kitty-text mb-1">URL Styling</h3>
8787
<p class="text-kitty-text-dim text-sm mb-4">Appearance of detected URLs in the terminal</p>
@@ -90,15 +90,15 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
9090
<div class="form-group">
9191
<label class="block text-sm font-medium text-kitty-text mb-2">URL Color</label>
9292
<app-color-input
93-
[value]="mouse.url_color || '#0087bd'"
93+
[value]="mouse().url_color || '#0087bd'"
9494
(valueChange)="updateColorMouse('url_color', $event)" />
9595
</div>
9696
9797
<div class="form-group">
9898
<label class="block text-sm font-medium text-kitty-text mb-2">URL Style</label>
9999
<select
100-
[(ngModel)]="mouse.url_style"
101-
(ngModelChange)="updateMouse()"
100+
[(ngModel)]="mouse().url_style"
101+
(ngModelChange)="helper.updateField('url_style', $event)"
102102
class="w-full px-4 py-2 bg-kitty-bg border border-kitty-border rounded-lg text-kitty-text focus:outline-none focus:ring-2 focus:ring-kitty-primary"
103103
>
104104
<option value="none">None</option>
@@ -187,7 +187,7 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
187187
</label>
188188
<input
189189
type="text"
190-
[ngModel]="mouse.paste_actions.join(',')"
190+
[ngModel]="mouse().paste_actions.join(',')"
191191
(ngModelChange)="setPasteActions($event)"
192192
class="w-full px-4 py-2 bg-kitty-bg border border-kitty-border rounded-lg text-kitty-text focus:outline-none focus:ring-2 focus:ring-kitty-primary font-mono text-sm"
193193
placeholder="quote-urls-at-prompt,confirm"
@@ -200,8 +200,8 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
200200
<span class="text-kitty-text-dim text-xs ml-2">Max time between clicks for double/triple click (seconds)</span>
201201
</label>
202202
<app-number-input
203-
[(ngModel)]="mouse.click_interval"
204-
(ngModelChange)="updateMouse()"
203+
[(ngModel)]="mouse().click_interval"
204+
(ngModelChange)="helper.updateField('click_interval', $event)"
205205
[min]="0.1"
206206
[max]="1"
207207
[step]="0.05"
@@ -340,33 +340,20 @@ import { ColorInputComponent } from '../../shared/color-input/color-input.compon
340340
styles: []
341341
})
342342
export class MouseFormComponent {
343-
private readonly configStore = inject(ConfigStoreService);
344-
345-
readonly advancedMode = computed(() => this.configStore.advancedMode());
346-
mouse: KittyMouseConfig = { ...this.configStore.configState().mouse };
347-
348-
constructor() {
349-
effect(() => {
350-
this.mouse = { ...this.configStore.configState().mouse };
351-
});
352-
}
353-
354-
updateMouse(): void {
355-
this.configStore.updateSection('mouse', { ...this.mouse });
356-
}
343+
readonly helper = createFormHelper('mouse');
344+
readonly mouse = this.helper.state.asReadonly();
357345

358346
setUrlPrefixes(value: string): void {
359-
this.mouse = { ...this.mouse, url_prefixes: value.split(',').map(s => s.trim()).filter(Boolean) };
360-
this.updateMouse();
347+
const prefixes = value.split(',').map(s => s.trim()).filter(Boolean);
348+
this.helper.updateField('url_prefixes', prefixes);
361349
}
362350

363351
setPasteActions(value: string): void {
364-
this.mouse = { ...this.mouse, paste_actions: value.split(',').map(s => s.trim()).filter(Boolean) };
365-
this.updateMouse();
352+
const actions = value.split(',').map(s => s.trim()).filter(Boolean);
353+
this.helper.updateField('paste_actions', actions);
366354
}
367355

368356
updateColorMouse(key: keyof KittyMouseConfig, value: string): void {
369-
this.mouse = { ...this.mouse, [key]: value };
370-
this.updateMouse();
357+
this.helper.updateField(key, value);
371358
}
372359
}

0 commit comments

Comments
 (0)