Skip to content

Commit 50242eb

Browse files
authored
Fix: 永続保存に対応する (#41)
2 parents 08d742b + c0cf363 commit 50242eb

17 files changed

Lines changed: 115 additions & 20 deletions

File tree

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
module.exports = {
2+
eslint: {
3+
// Warning: This allows production builds to successfully complete even if
4+
// your project has ESLint errors.
5+
ignoreDuringBuilds: true,
6+
},
27
"extends": [
38
"next/core-web-vitals",
49
"plugin:import/recommended",

src/app/base64/useBase64.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import { useCustomForm } from '@/components/common/Form/useCustomForm';
3+
import { useFormPersistence } from '@/hooks/useFormPersistence';
34

45
type Base64Form = {
56
input: string;
@@ -13,10 +14,14 @@ export const useBase64 = () => {
1314
const methods = useCustomForm<Base64Form>({
1415
defaultValues: DEFAULT_VALUES,
1516
});
16-
const { watch } = methods;
17+
const { watch, setValue } = methods;
1718
const [output, setOutput] = useState('');
1819
const input = watch('input', DEFAULT_VALUES.input);
1920

21+
useFormPersistence('base64', methods, (defaultValues) => {
22+
setValue('input', defaultValues?.input);
23+
});
24+
2025
useEffect(() => {
2126
if (typeof window === 'undefined' || input.trim() === '') {
2227
setOutput('');

src/app/character_count/CharacterCount.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { LabelInput } from '@/components/common/Form/LabelInput';
1818
import { useCustomForm } from '@/components/common/Form/useCustomForm';
1919
import { PageTitle } from '@/components/common/PageTitle';
2020
import { PanelHeader } from '@/components/common/PanelHeader';
21+
import { useFormPersistence } from '@/hooks/useFormPersistence';
2122

2223
type characterCountForm = {
2324
input: string;
@@ -29,7 +30,10 @@ export const CharacterCount: FC = () => {
2930
input: '',
3031
},
3132
});
32-
const { control, watch } = methods;
33+
const { control, watch, setValue } = methods;
34+
useFormPersistence('character_count', methods, (defaultValues) => {
35+
setValue('input', defaultValues?.input);
36+
});
3337

3438
const title = '文字数カウント';
3539
const input = watch('input', '');

src/app/character_replace/useCharacterReplace.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useState } from 'react';
22
import { useCustomForm } from '@/components/common/Form/useCustomForm';
3+
import { useFormPersistence } from '@/hooks/useFormPersistence';
34

45
type CharacterReplaceForm = {
56
input: string;
@@ -18,9 +19,13 @@ export const useCharacterReplace = () => {
1819
const methods = useCustomForm<CharacterReplaceForm>({
1920
defaultValues: DEFAULT_VALUES,
2021
});
21-
const { watch } = methods;
22+
const { watch, setValue } = methods;
2223
const [inputCount, setInputCount] = useState(3);
2324

25+
useFormPersistence('character_replace', methods, (defaultValues) => {
26+
setValue('input', defaultValues?.input);
27+
});
28+
2429
// @ts-ignore
2530
const numberArray = [...Array(inputCount).keys()].map((i) => ++i);
2631

src/app/date_converter/useDateConverter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMemo, useEffect, useCallback, useState, ChangeEventHandler, ChangeEv
33
import TIME_ZONES from 'timezones-list';
44
import { useCustomForm } from '@/components/common/Form/useCustomForm';
55
import { dayjs } from '@/lib/dayjs';
6+
import { useFormPersistence } from '@/hooks/useFormPersistence';
67

78
type dateConverterForm = {
89
inputDate: Dayjs | undefined;
@@ -21,6 +22,13 @@ export const useDateConverter = () => {
2122
},
2223
});
2324
const { watch, control, setValue, getValues } = methods;
25+
useFormPersistence('date_converter', methods, (defaultValues) => {
26+
setValue('inputDate', defaultValues?.inputDate);
27+
setValue('inputUnixTime', defaultValues?.inputUnixTime);
28+
setValue('timezone', defaultValues?.timezone);
29+
setValue('customFormat', defaultValues?.customFormat);
30+
});
31+
2432
const timezones = useMemo(
2533
() => TIME_ZONES.map(({ label, tzCode }) => ({ label: label, value: tzCode })),
2634
[],

src/app/date_diff/useDateDiff.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Dayjs } from 'dayjs';
22
import { useCallback } from 'react';
33
import { useCustomForm } from '@/components/common/Form/useCustomForm';
44
import { dayjs } from '@/lib/dayjs';
5+
import { useFormPersistence } from '@/hooks/useFormPersistence';
56

67
type DateDiffForm = {
78
inputDate1: Dayjs | undefined;
@@ -19,6 +20,12 @@ export const useDateDiff = () => {
1920
defaultValues: DEFAULT_VALUES,
2021
});
2122
const { watch, control, setValue, getValues } = methods;
23+
useFormPersistence('date_diff', methods, (defaultValues) => {
24+
setValue('inputDate1', defaultValues?.inputDate1);
25+
setValue('inputDate2', defaultValues?.inputDate2);
26+
setValue('isFormatFloat', defaultValues?.isFormatFloat);
27+
});
28+
2229
const date1 = watch('inputDate1');
2330
const date2 = watch('inputDate2');
2431
const isFormatInt = watch('isFormatFloat');

src/app/diff/useDiff.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { useCustomForm } from '@/components/common/Form/useCustomForm';
3+
import { useFormPersistence } from '@/hooks/useFormPersistence';
34

45
type DiffForm = {
56
original: string;
@@ -16,6 +17,10 @@ export const useDiff = () => {
1617
defaultValues: DEFAULT_VALUES,
1718
});
1819
const { watch, resetField, setValue } = methods;
20+
useFormPersistence('diff', methods, (defaultValues) => {
21+
setValue('original', defaultValues?.original);
22+
setValue('modified', defaultValues?.modified);
23+
});
1924

2025
const original = watch('original', DEFAULT_VALUES.original);
2126
const modified = watch('modified', DEFAULT_VALUES.modified);

src/app/hash/useHash.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createHash as cryptoCreateHash } from 'crypto';
22
import { useCallback } from 'react';
33
import { useCustomForm } from '@/components/common/Form/useCustomForm';
44
import { HASH_ALGORITHMS } from '@/lib/hashAlgorithms';
5+
import { useFormPersistence } from '@/hooks/useFormPersistence';
56

67
type Base64Form = {
78
input: string;
@@ -17,7 +18,11 @@ export const useHash = () => {
1718
const methods = useCustomForm<Base64Form>({
1819
defaultValues: DEFAULT_VALUES,
1920
});
20-
const { watch } = methods;
21+
const { watch, setValue } = methods;
22+
useFormPersistence('hash', methods, (defaultValues) => {
23+
setValue('input', defaultValues?.input);
24+
setValue('isUppercase', defaultValues?.isUppercase);
25+
});
2126

2227
const input = watch('input', DEFAULT_VALUES.input);
2328
const isUppercase = watch('isUppercase', DEFAULT_VALUES.isUppercase);

src/app/image_generator/useImageGenerator.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AggregationColor } from 'antd/es/color-picker/color';
33
import { useCallback, useState } from 'react';
44
import { getPresetSize } from '@/app/image_generator/presetSize';
55
import { useCustomForm } from '@/components/common/Form/useCustomForm';
6+
import { useFormPersistence } from '@/hooks/useFormPersistence';
67

78
type ImageGeneratorForm = {
89
wight: number;
@@ -65,6 +66,16 @@ export const useImageGenerator = () => {
6566
const { getValues, setValue } = methods;
6667
const [src, setSrc] = useState('');
6768

69+
useFormPersistence('image_generator', methods, (defaultValues) => {
70+
setValue('wight', defaultValues?.wight);
71+
setValue('height', defaultValues?.height);
72+
setValue('type', defaultValues?.type);
73+
setValue('bgColor', defaultValues?.bgColor);
74+
setValue('textColor', defaultValues?.textColor);
75+
setValue('tab', defaultValues?.tab);
76+
setValue('text', defaultValues?.text);
77+
setValue('textSize', defaultValues?.textSize);
78+
});
6879
const onClickGenerate = useCallback(() => {
6980
const values = getValues();
7081
switch (values.tab) {

src/app/json_formatter/useJsonFormatter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react';
22
import { format } from '@/app/json_formatter/jsonFormatterLib';
33
import { useCustomForm } from '@/components/common/Form/useCustomForm';
4+
import { useFormPersistence } from '@/hooks/useFormPersistence';
45

56
type JsonFormatForm = {
67
input: string;
@@ -18,7 +19,13 @@ export const useJsonFormatter = () => {
1819
const methods = useCustomForm<JsonFormatForm>({
1920
defaultValues: DEFAULT_VALUES,
2021
});
21-
const { watch } = methods;
22+
const { watch, setValue } = methods;
23+
24+
useFormPersistence('json_formatter', methods, (defaultValues) => {
25+
setValue('input', defaultValues?.input);
26+
setValue('output', defaultValues?.output);
27+
setValue('indentSpace', defaultValues?.indentSpace);
28+
});
2229

2330
const input = watch('input', DEFAULT_VALUES.input);
2431
const output = format(input, watch('indentSpace'));

0 commit comments

Comments
 (0)