mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-22 03:46:22 +03:00
refactor: note inputs
This commit is contained in:
parent
06e8f6ce41
commit
ff9eccc887
2 changed files with 79 additions and 47 deletions
|
@ -14,9 +14,12 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/* eslint-disable react-refresh/only-export-components */
|
||||||
import { CheckBox } from "./checkbox";
|
import { CheckBox } from "./checkbox";
|
||||||
import { inputStyle, settingsAddInput } from "./styles";
|
import { inputStyle, settingsAddInput } from "./styles";
|
||||||
|
import { ButtonWithIcon } from "./button";
|
||||||
|
import { Complete } from "../components/openai";
|
||||||
|
import { DocumentTextIcon } from "@heroicons/react/24/outline";
|
||||||
|
|
||||||
function SettingsCheckBox({ label, title, className, settingName, onClick }) {
|
function SettingsCheckBox({ label, title, className, settingName, onClick }) {
|
||||||
return (
|
return (
|
||||||
|
@ -109,10 +112,73 @@ function SettingsSection({ name, children }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function NoteNameInput({ value, onChange, preview }) {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className={`mb-2 md:w-1/6 w-full ${inputStyle} ${
|
||||||
|
preview ? "hidden" : ""
|
||||||
|
}`}
|
||||||
|
placeholder={locals.NoteName}
|
||||||
|
maxLength={64}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function NoteTextArea({ value, onChange, preview }) {
|
||||||
|
return (
|
||||||
|
<textarea
|
||||||
|
className={`
|
||||||
|
${inputStyle}
|
||||||
|
w-full
|
||||||
|
${preview ? "hidden" : ""}
|
||||||
|
`}
|
||||||
|
rows="10"
|
||||||
|
placeholder={locals.NotePlaceholder}
|
||||||
|
maxLength={5000}
|
||||||
|
onChange={onChange}
|
||||||
|
value={value}
|
||||||
|
></textarea>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function NotesAdditionalSettings() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{settings.additionalFeatures && (
|
||||||
|
<div className="justify-self-start lg:justify-self-start">
|
||||||
|
<SettingsSection name={locals.AdditionalFeatures}>
|
||||||
|
{!!settings.openAiKey && (
|
||||||
|
<ButtonWithIcon
|
||||||
|
icon={DocumentTextIcon}
|
||||||
|
text={locals.AIComplete}
|
||||||
|
className="m-1"
|
||||||
|
w="w-full"
|
||||||
|
onClick={() => {
|
||||||
|
Complete(setText, textUpdate);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<SettingsCheckBox
|
||||||
|
label={locals.CollabEdit}
|
||||||
|
settingName="CollabEdit"
|
||||||
|
/>
|
||||||
|
</SettingsSection>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
SettingsCheckBox,
|
SettingsCheckBox,
|
||||||
SettingsTextInput,
|
SettingsTextInput,
|
||||||
SettingsSelectInput,
|
SettingsSelectInput,
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
setSetting,
|
setSetting,
|
||||||
|
NoteNameInput,
|
||||||
|
NoteTextArea,
|
||||||
|
NotesAdditionalSettings,
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,10 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ButtonWithIcon } from "../components/button";
|
import { ButtonWithIcon } from "../components/button";
|
||||||
import {
|
import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
|
||||||
ChevronDoubleRightIcon,
|
|
||||||
DocumentTextIcon,
|
|
||||||
} from "@heroicons/react/24/outline";
|
|
||||||
import { CheckBox } from "../components/checkbox";
|
import { CheckBox } from "../components/checkbox";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import RenderMarkdown from "../components/markdown";
|
import RenderMarkdown from "../components/markdown";
|
||||||
|
@ -33,11 +30,11 @@ import remarkStringify from "remark-stringify";
|
||||||
import remarkGfm from "remark-gfm";
|
import remarkGfm from "remark-gfm";
|
||||||
import remarkMath from "remark-math";
|
import remarkMath from "remark-math";
|
||||||
import {
|
import {
|
||||||
|
NoteNameInput,
|
||||||
|
NoteTextArea,
|
||||||
|
NotesAdditionalSettings,
|
||||||
SettingsCheckBox,
|
SettingsCheckBox,
|
||||||
SettingsSection,
|
|
||||||
} from "../components/settingsInputs";
|
} from "../components/settingsInputs";
|
||||||
import { inputStyle } from "../components/styles";
|
|
||||||
import { Complete } from "../components/openai";
|
|
||||||
|
|
||||||
function nameUpdate(val, force) {
|
function nameUpdate(val, force) {
|
||||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
||||||
|
@ -127,13 +124,7 @@ function CreateNote() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input
|
<NoteNameInput
|
||||||
type="text"
|
|
||||||
className={`mb-2 md:w-1/6 w-full ${inputStyle} ${
|
|
||||||
preview ? "hidden" : ""
|
|
||||||
}`}
|
|
||||||
placeholder={locals.NoteName}
|
|
||||||
maxLength={64}
|
|
||||||
value={localStorage.getItem("NoteName") || ""}
|
value={localStorage.getItem("NoteName") || ""}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setName(e.target.value);
|
setName(e.target.value);
|
||||||
|
@ -146,16 +137,11 @@ function CreateNote() {
|
||||||
}, window.socketTimeout);
|
}, window.socketTimeout);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
preview={preview}
|
||||||
/>
|
/>
|
||||||
<textarea
|
|
||||||
className={`
|
<NoteTextArea
|
||||||
${inputStyle}
|
value={localStorage.getItem("NoteText") || ""}
|
||||||
w-full
|
|
||||||
${preview ? "hidden" : ""}
|
|
||||||
`}
|
|
||||||
rows="10"
|
|
||||||
placeholder={locals.NotePlaceholder}
|
|
||||||
maxLength={5000}
|
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setText(e.target.value);
|
setText(e.target.value);
|
||||||
localStorage.setItem("NoteText", e.target.value);
|
localStorage.setItem("NoteText", e.target.value);
|
||||||
|
@ -167,8 +153,8 @@ function CreateNote() {
|
||||||
}, window.socketTimeout);
|
}, window.socketTimeout);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
value={localStorage.getItem("NoteText") || ""}
|
preview={preview}
|
||||||
></textarea>
|
/>
|
||||||
|
|
||||||
{preview && (
|
{preview && (
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2">
|
<div className="grid grid-cols-1 lg:grid-cols-2">
|
||||||
|
@ -213,27 +199,7 @@ function CreateNote() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{settings.additionalFeatures && (
|
<NotesAdditionalSettings />
|
||||||
<div className="justify-self-start lg:justify-self-start">
|
|
||||||
<SettingsSection name={locals.AdditionalFeatures}>
|
|
||||||
{!!settings.openAiKey && (
|
|
||||||
<ButtonWithIcon
|
|
||||||
icon={DocumentTextIcon}
|
|
||||||
text={locals.AIComplete}
|
|
||||||
className="m-1"
|
|
||||||
w="w-full"
|
|
||||||
onClick={() => {
|
|
||||||
Complete(setText, textUpdate);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<SettingsCheckBox
|
|
||||||
label={locals.CollabEdit}
|
|
||||||
settingName="CollabEdit"
|
|
||||||
/>
|
|
||||||
</SettingsSection>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue