-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fc356c
commit e0c99fc
Showing
16 changed files
with
392 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export type setStateFun<S> = (newState: Partial<S>) => void | ||
export type SetStateFun<S> = (newState: Partial<S>) => void | ||
|
||
export function getClassState<S>( | ||
useState: [S, React.Dispatch<React.SetStateAction<S>>] | ||
): [S, setStateFun<S>] { | ||
): [S, SetStateFun<S>] { | ||
const setState = (newState: Partial<S>) => useState[1]((preState) => ({ ...preState, ...newState })); | ||
return [useState[0], setState]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const chat = { | ||
const chat = { | ||
title: { | ||
'zh-CN': '聊天编辑', | ||
'zh-TW': '聊天編輯', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { i18nContents } from ".."; | ||
|
||
const main: i18nContents = { | ||
setting: { | ||
'zh-CN': '设置', | ||
'zh-TW': '設定', | ||
}, | ||
setLocale: { | ||
'zh-CN': '选择语言', | ||
'zh-TW': '選取語言', | ||
}, | ||
locales: { | ||
'zh-CN': '中文(简体)', | ||
'zh-TW': '中文(繁體)', | ||
}, | ||
setAnimation: { | ||
'zh-CN': '设置开屏动画模式', | ||
'zh-TW': '設定開屏動畫模式', | ||
}, | ||
animationTnone: { | ||
'zh-CN': '从不', | ||
'zh-TW': '從不', | ||
}, | ||
animationTfirst: { | ||
'zh-CN': '首次', | ||
'zh-TW': '首次', | ||
}, | ||
animationTevery: { | ||
'zh-CN': '每次', | ||
'zh-TW': '每次', | ||
}, | ||
done: { | ||
'zh-CN': '确定', | ||
'zh-TW': '確定', | ||
}, | ||
} | ||
export default main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import styles from '@/styles/MainNode.module.scss'; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import Repeat from './repeat'; | ||
import { useForm } from 'react-hook-form'; | ||
import { SetStateFun } from './extraReact'; | ||
import { getClassState } from './extraReact'; | ||
|
||
interface SettingOption { | ||
type: string; | ||
label: string; | ||
} | ||
|
||
interface OptionSO<T extends string = string> extends SettingOption { | ||
type: 'option'; | ||
values?: T[]; | ||
defaultValue?: T; | ||
getValue: (value: T, index: number, array: T[]) => React.ReactNode; | ||
} | ||
|
||
type OptionTypes = OptionSO; | ||
|
||
interface SettingFormProps<N extends string> { | ||
option: Record<N, OptionTypes>; | ||
done: string; | ||
onSubmit: (data: Record<N, string>) => any; | ||
} | ||
|
||
export function SettingForm<N extends string>({ option, done, onSubmit }: SettingFormProps<N>) { | ||
const { register, handleSubmit } = useForm(); | ||
let optionArray: (OptionTypes & { name: N })[] = []; | ||
for (let o in option) { | ||
let opt = option[o]; | ||
optionArray.push(Object.assign(opt, { name: o })); | ||
} | ||
return ( | ||
<form onSubmit={handleSubmit(data => { | ||
const dataKeyAsN = data as Record<N, string>; | ||
onSubmit(dataKeyAsN); | ||
})} id={styles.settings}> | ||
<Repeat | ||
variable={0} | ||
repeat={optionArray.length} | ||
func={i => i + 1} | ||
components={i => { | ||
const o = optionArray[i]; | ||
return ( | ||
<label> | ||
{o.label} | ||
{o.type === 'option' && ( | ||
<select {...register(o.name)} defaultValue={o.defaultValue}> | ||
{o.values?.map((v, i, a) => ( | ||
<React.Fragment key={i}> | ||
{o.getValue(v, i, a)} | ||
</React.Fragment> | ||
))} | ||
</select> | ||
)} | ||
</label> | ||
); | ||
}} | ||
/> | ||
<button type='submit'>{done}</button> | ||
</form> | ||
) | ||
} | ||
|
||
export interface SettingState { | ||
locale?: string; | ||
animation?: 'none' | 'first' | 'every'; | ||
} | ||
|
||
export interface SettingArg { | ||
setting: SettingState; | ||
setSetting: SetStateFun<SettingState>; | ||
} | ||
|
||
export function useSetting(state?: SettingState) { | ||
const [setting, setSetting] = getClassState(useState<SettingState>(state || {})); | ||
useEffect(() => { | ||
let setting: string = window.localStorage.set; | ||
if (setting !== undefined) { | ||
setSetting(JSON.parse(setting)); | ||
} | ||
}, []); | ||
return { setting, setSetting }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e0c99fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
momotalk-editor – ./
momotalk-editor-slouchwind.vercel.app
momotalk-editor.vercel.app
momotalk.slouchwind.tk
momotalk-editor-git-main-slouchwind.vercel.app