Skip to content

Commit a1b031b

Browse files
committed
レビュー受けての修正
1 parent f15b958 commit a1b031b

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

frontend/src/App.svelte

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88
import { type Problem, type ClosedRange, createValidRange } from "./utils/types";
99
import { cacheInput, loadLastInput } from "./cacher";
1010
11-
const maxDiff = 3854;
12-
const minDiff = 0;
11+
const MinDiff:number = 0;
12+
const MaxDiff:number = 3854;
1313
1414
let cachedInput : ClosedRange | null = loadLastInput();
1515
let currentInput : ClosedRange | null;
1616
17-
let under_diff = $state<number>(cachedInput ? cachedInput.min : minDiff);
18-
let over_diff = $state<number>(cachedInput ? cachedInput.max : maxDiff);
17+
let under_diff = $state<number>(cachedInput ? cachedInput.min : MinDiff);
18+
let over_diff = $state<number>(cachedInput ? cachedInput.max : MaxDiff);
1919
2020
let errors = $derived({
21-
rangeError: under_diff > over_diff,
21+
rangeError: !(currentInput = createValidRange(under_diff, over_diff)),
2222
isMinusUnderDiff: under_diff < 0,
2323
isMinusOverDiff: over_diff < 0,
24-
invalidRange: !(currentInput = createValidRange(under_diff, over_diff))
2524
});
2625
2726
let result = $state<Problem | null>(null);
@@ -77,8 +76,6 @@
7776
<p class="text-destructive mb-2 text-sm">最高Diffが負の値になっています。</p>
7877
{:else if errors.isMinusUnderDiff}
7978
<p class="text-destructive mb-2 text-sm">最低Diffが負の値になっています</p>
80-
{:else if errors.invalidRange}
81-
<p class="text-destructive mb-2 text-sm">不正なDiff範囲になっています。</p>
8279
{/if}
8380

8481
<div class="flex items-center gap-2">

frontend/src/cacher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { ClosedRange } from './utils/types';
22

33
const rangeKey : string = 'lastDiff';
44

5-
export function cacheInput(range : ClosedRange): void {
6-
localStorage.setItem(rangeKey, JSON.stringify(range));
5+
export const cacheInput = (range : ClosedRange): void => {
6+
localStorage.setItem(rangeKey, JSON.stringify(range));
77
}
8-
export function loadLastInput(): ClosedRange | null {
9-
const data = localStorage.getItem(rangeKey);
10-
return data ? JSON.parse(data) as ClosedRange : null;
8+
export const loadLastInput = (): ClosedRange | null => {
9+
const data = localStorage.getItem(rangeKey);
10+
return data ? JSON.parse(data) as ClosedRange : null;
1111
}

frontend/src/utils/types.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ export type ClosedRange = {
1111
} & { readonly __brand: unique symbol };
1212

1313
// for validation
14-
export function createValidRange(min: number, max: number): ClosedRange | null {
15-
if (min > max) return null;
16-
17-
return {
18-
min,
19-
max,
20-
__brand: Symbol('ClosedRange') as never
21-
};
14+
export const createValidRange = (min: number, max: number): ClosedRange | null => {
15+
return min>max ? null : {min, max, __brand: Symbol('ClosedRange') as never};
2216
}

0 commit comments

Comments
 (0)