mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-12-23 01:13:45 +03:00
feat: noteEditing
This commit is contained in:
parent
ff9eccc887
commit
0a0f0f950a
6 changed files with 88 additions and 28 deletions
|
@ -17,10 +17,10 @@
|
|||
|
||||
import { Configuration, OpenAIApi } from "openai";
|
||||
|
||||
async function Complete(setText, textUpdate) {
|
||||
async function Complete(text) {
|
||||
document.body.style.cursor = "wait";
|
||||
|
||||
let initText = localStorage.getItem("NoteText");
|
||||
let initText = text;
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: settings.openAiKey,
|
||||
|
@ -37,16 +37,9 @@ async function Complete(setText, textUpdate) {
|
|||
logprobs: null,
|
||||
});
|
||||
|
||||
let totalText = initText + response.data.choices[0].text;
|
||||
|
||||
localStorage.setItem("NoteText", totalText);
|
||||
setText(totalText);
|
||||
|
||||
if (settings.CollabEdit === true) {
|
||||
textUpdate(totalText, true);
|
||||
}
|
||||
|
||||
document.body.style.cursor = "default";
|
||||
|
||||
return initText + response.data.choices[0].text;
|
||||
}
|
||||
|
||||
export { Complete };
|
||||
|
|
|
@ -112,7 +112,7 @@ function SettingsSection({ name, children }) {
|
|||
);
|
||||
}
|
||||
|
||||
function NoteNameInput({ value, onChange, preview }) {
|
||||
function NoteNameInput({ value, onChange, preview = false }) {
|
||||
return (
|
||||
<input
|
||||
type="text"
|
||||
|
@ -121,13 +121,13 @@ function NoteNameInput({ value, onChange, preview }) {
|
|||
}`}
|
||||
placeholder={locals.NoteName}
|
||||
maxLength={64}
|
||||
value={value}
|
||||
defaultValue={value}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NoteTextArea({ value, onChange, preview }) {
|
||||
function NoteTextArea({ value, onChange, preview = false }) {
|
||||
return (
|
||||
<textarea
|
||||
className={`
|
||||
|
@ -139,12 +139,15 @@ function NoteTextArea({ value, onChange, preview }) {
|
|||
placeholder={locals.NotePlaceholder}
|
||||
maxLength={5000}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
defaultValue={value}
|
||||
></textarea>
|
||||
);
|
||||
}
|
||||
|
||||
function NotesAdditionalSettings() {
|
||||
function NotesAdditionalSettings({
|
||||
noteText = localStorage.getItem("NoteText"),
|
||||
onClick,
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{settings.additionalFeatures && (
|
||||
|
@ -157,7 +160,9 @@ function NotesAdditionalSettings() {
|
|||
className="m-1"
|
||||
w="w-full"
|
||||
onClick={() => {
|
||||
Complete(setText, textUpdate);
|
||||
let text = Complete(noteText);
|
||||
|
||||
onClick(text);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -75,6 +75,7 @@ let en = {
|
|||
LocalNote: "Local",
|
||||
Menu: "Menu",
|
||||
SourceCode: "Source code",
|
||||
Edit: "Edit",
|
||||
};
|
||||
|
||||
export default en;
|
||||
|
|
|
@ -77,6 +77,7 @@ let ru = {
|
|||
PublishNote: "Публичная",
|
||||
Menu: "Меню",
|
||||
SourceCode: "Исходный код",
|
||||
Edit: "Изменить",
|
||||
};
|
||||
|
||||
export default ru;
|
||||
|
|
|
@ -199,7 +199,16 @@ function CreateNote() {
|
|||
/>
|
||||
</div>
|
||||
|
||||
<NotesAdditionalSettings />
|
||||
<NotesAdditionalSettings
|
||||
onClick={(text) => {
|
||||
localStorage.setItem("NoteText", text);
|
||||
setText(text);
|
||||
|
||||
if (settings.CollabEdit === true) {
|
||||
textUpdate(text, true);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -16,14 +16,27 @@
|
|||
*/
|
||||
|
||||
import { useParams } from "react-router-dom";
|
||||
import { ChevronDoubleLeftIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
ChevronDoubleLeftIcon,
|
||||
PencilIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { ButtonWithIcon } from "../components/button";
|
||||
import Note from "../components/note";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
NoteNameInput,
|
||||
NoteTextArea,
|
||||
NotesAdditionalSettings,
|
||||
} from "../components/settingsInputs";
|
||||
|
||||
function NotePage() {
|
||||
let params = useParams();
|
||||
|
||||
let note = localStorage.getObj("Notes")[params.id];
|
||||
let notes = localStorage.getObj("Notes");
|
||||
let note = notes[params.id];
|
||||
|
||||
let [edit, setEdit] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
|
@ -34,23 +47,61 @@ function NotePage() {
|
|||
text={locals.Notes}
|
||||
/>
|
||||
|
||||
{note ? <Note note={note} /> : <div>{locals.NoteNotExists}</div>}
|
||||
{note ? (
|
||||
edit ? (
|
||||
<>
|
||||
<NoteNameInput
|
||||
value={note.name}
|
||||
onChange={(e) => (note.name = e.target.value)}
|
||||
/>
|
||||
<NoteTextArea
|
||||
value={note.text}
|
||||
onChange={(e) => (note.text = e.target.value)}
|
||||
/>
|
||||
|
||||
<NotesAdditionalSettings
|
||||
noteText={note.text}
|
||||
onClick={(text) => {
|
||||
note.text = text;
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Note note={note} />
|
||||
)
|
||||
) : (
|
||||
<div>{locals.NoteNotExists}</div>
|
||||
)}
|
||||
{note && (
|
||||
<div className="grid grid-cols-1">
|
||||
<div className="justify-self-center lg:justify-self-end">
|
||||
<ButtonWithIcon
|
||||
className="mt-4"
|
||||
href="/notes"
|
||||
text={locals.Delete}
|
||||
icon={TrashIcon}
|
||||
text={locals.Edit}
|
||||
icon={PencilIcon}
|
||||
onClick={() => {
|
||||
let notesObj = localStorage.getObj("Notes");
|
||||
setEdit(!edit);
|
||||
|
||||
delete notesObj[params.id];
|
||||
|
||||
localStorage.setObj("Notes", notesObj);
|
||||
if (edit) {
|
||||
localStorage.setObj("Notes", notes);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{!edit && (
|
||||
<ButtonWithIcon
|
||||
className="mt-4"
|
||||
href="/notes"
|
||||
text={locals.Delete}
|
||||
icon={TrashIcon}
|
||||
onClick={() => {
|
||||
let notesObj = localStorage.getObj("Notes");
|
||||
|
||||
delete notesObj[params.id];
|
||||
|
||||
localStorage.setObj("Notes", notesObj);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
Loading…
Add table
Reference in a new issue