-
Notifications
You must be signed in to change notification settings - Fork 466
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
pompurin404
committed
Aug 5, 2024
1 parent
8d7ae19
commit 1cc68b5
Showing
10 changed files
with
343 additions
and
61 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
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,77 @@ | ||
import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from '@nextui-org/react' | ||
import React, { useEffect, useState } from 'react' | ||
import MonacoEditor, { monaco } from 'react-monaco-editor' | ||
import { useTheme } from 'next-themes' | ||
import { getProfileStr, setProfileStr } from '@renderer/utils/ipc' | ||
interface Props { | ||
id: string | ||
onClose: () => void | ||
} | ||
const EditFileModal: React.FC<Props> = (props) => { | ||
const { id, onClose } = props | ||
const [currData, setCurrData] = useState('') | ||
const { theme } = useTheme() | ||
|
||
const editorDidMount = (editor: monaco.editor.IStandaloneCodeEditor): void => { | ||
window.electron.ipcRenderer.on('resize', () => { | ||
editor.layout() | ||
}) | ||
} | ||
|
||
const editorWillUnmount = (editor: monaco.editor.IStandaloneCodeEditor): void => { | ||
window.electron.ipcRenderer.removeAllListeners('resize') | ||
editor.dispose() | ||
} | ||
|
||
const getContent = async (): Promise<void> => { | ||
setCurrData(await getProfileStr(id)) | ||
} | ||
|
||
useEffect(() => { | ||
getContent() | ||
}, []) | ||
|
||
return ( | ||
<Modal size="5xl" hideCloseButton isOpen={true} scrollBehavior="inside"> | ||
<ModalContent className="h-full w-[calc(100%-100px)]"> | ||
<ModalHeader className="flex">编辑订阅</ModalHeader> | ||
<ModalBody className="h-full"> | ||
<MonacoEditor | ||
height="100%" | ||
language="yaml" | ||
value={currData} | ||
theme={theme === 'dark' ? 'vs-dark' : 'vs'} | ||
options={{ | ||
minimap: { | ||
enabled: false | ||
}, | ||
mouseWheelZoom: true, | ||
fontFamily: `Fira Code, JetBrains Mono, Roboto Mono, "Source Code Pro", Consolas, Menlo, Monaco, monospace, "Courier New", "Apple Color Emoji"`, | ||
fontLigatures: true, // 连字符 | ||
smoothScrolling: true // 平滑滚动 | ||
}} | ||
editorDidMount={editorDidMount} | ||
editorWillUnmount={editorWillUnmount} | ||
onChange={(value) => setCurrData(value)} | ||
/> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button variant="light" onPress={onClose}> | ||
取消 | ||
</Button> | ||
<Button | ||
color="primary" | ||
onPress={async () => { | ||
await setProfileStr(id, currData) | ||
onClose() | ||
}} | ||
> | ||
确认 | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default EditFileModal |
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,79 @@ | ||
import { | ||
Modal, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
Input | ||
} from '@nextui-org/react' | ||
import React, { useState } from 'react' | ||
import SettingItem from '../base/base-setting-item' | ||
interface Props { | ||
item: IProfileItem | ||
updateProfileItem: (item: IProfileItem) => Promise<void> | ||
onClose: () => void | ||
} | ||
const EditInfoModal: React.FC<Props> = (props) => { | ||
const { item, updateProfileItem, onClose } = props | ||
const [values, setValues] = useState(item) | ||
|
||
const onSave = async (): Promise<void> => { | ||
await updateProfileItem(values) | ||
onClose() | ||
} | ||
|
||
return ( | ||
<Modal hideCloseButton isOpen={true} scrollBehavior="inside"> | ||
<ModalContent> | ||
<ModalHeader className="flex">编辑信息</ModalHeader> | ||
<ModalBody> | ||
<SettingItem title="名称"> | ||
<Input | ||
size="sm" | ||
className="w-[200px]" | ||
value={values.name} | ||
onValueChange={(v) => { | ||
setValues({ ...values, name: v }) | ||
}} | ||
/> | ||
</SettingItem> | ||
{values.url && ( | ||
<SettingItem title="订阅地址"> | ||
<Input | ||
size="sm" | ||
className="w-[200px]" | ||
value={values.url} | ||
onValueChange={(v) => { | ||
setValues({ ...values, url: v }) | ||
}} | ||
/> | ||
</SettingItem> | ||
)} | ||
|
||
<SettingItem title="更新间隔(分钟)"> | ||
<Input | ||
size="sm" | ||
type="number" | ||
className="w-[200px]" | ||
value={values.interval?.toString() ?? ''} | ||
onValueChange={(v) => { | ||
setValues({ ...values, interval: parseInt(v) }) | ||
}} | ||
/> | ||
</SettingItem> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button variant="light" onPress={onClose}> | ||
取消 | ||
</Button> | ||
<Button color="primary" onPress={onSave}> | ||
保存 | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default EditInfoModal |
Oops, something went wrong.