mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
refactor(react/dialogs): solve client errors
This commit is contained in:
parent
da1f18c60f
commit
d3519b3059
@ -39,7 +39,7 @@ export interface Suggestion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
container?: HTMLElement;
|
container?: HTMLElement | null;
|
||||||
fastSearch?: boolean;
|
fastSearch?: boolean;
|
||||||
allowCreatingNotes?: boolean;
|
allowCreatingNotes?: boolean;
|
||||||
allowJumpToSearchNotes?: boolean;
|
allowJumpToSearchNotes?: boolean;
|
||||||
|
@ -21,7 +21,7 @@ interface ExportDialogProps {
|
|||||||
|
|
||||||
function ExportDialogComponent() {
|
function ExportDialogComponent() {
|
||||||
const [ opts, setOpts ] = useState<ExportDialogProps>();
|
const [ opts, setOpts ] = useState<ExportDialogProps>();
|
||||||
const [ exportType, setExportType ] = useState(opts?.defaultType ?? "subtree");
|
const [ exportType, setExportType ] = useState<string>(opts?.defaultType ?? "subtree");
|
||||||
const [ subtreeFormat, setSubtreeFormat ] = useState("html");
|
const [ subtreeFormat, setSubtreeFormat ] = useState("html");
|
||||||
const [ singleFormat, setSingleFormat ] = useState("html");
|
const [ singleFormat, setSingleFormat ] = useState("html");
|
||||||
const [ opmlVersion, setOpmlVersion ] = useState("2.0");
|
const [ opmlVersion, setOpmlVersion ] = useState("2.0");
|
||||||
|
@ -52,7 +52,11 @@ function JumpToNoteDialogComponent() {
|
|||||||
setIsCommandMode(text.startsWith(">"));
|
setIsCommandMode(text.startsWith(">"));
|
||||||
}, [ text ]);
|
}, [ text ]);
|
||||||
|
|
||||||
async function onItemSelected(suggestion: Suggestion) {
|
async function onItemSelected(suggestion?: Suggestion | null) {
|
||||||
|
if (!suggestion) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setShown(false);
|
setShown(false);
|
||||||
if (suggestion.notePath) {
|
if (suggestion.notePath) {
|
||||||
appContext.tabManager.getActiveContext()?.setNote(suggestion.notePath);
|
appContext.tabManager.getActiveContext()?.setNote(suggestion.notePath);
|
||||||
|
@ -8,7 +8,7 @@ import Button from "../react/Button";
|
|||||||
import Modal from "../react/Modal";
|
import Modal from "../react/Modal";
|
||||||
import ReactBasicWidget from "../react/ReactBasicWidget";
|
import ReactBasicWidget from "../react/ReactBasicWidget";
|
||||||
import hoisted_note from "../../services/hoisted_note";
|
import hoisted_note from "../../services/hoisted_note";
|
||||||
import type { RecentChangesRow } from "@triliumnext/commons";
|
import type { RecentChangeRow } from "@triliumnext/commons";
|
||||||
import froca from "../../services/froca";
|
import froca from "../../services/froca";
|
||||||
import { formatDateTime } from "../../utils/formatters";
|
import { formatDateTime } from "../../utils/formatters";
|
||||||
import link from "../../services/link";
|
import link from "../../services/link";
|
||||||
@ -18,7 +18,7 @@ import useTriliumEvent from "../react/hooks";
|
|||||||
|
|
||||||
function RecentChangesDialogComponent() {
|
function RecentChangesDialogComponent() {
|
||||||
const [ ancestorNoteId, setAncestorNoteId ] = useState<string>();
|
const [ ancestorNoteId, setAncestorNoteId ] = useState<string>();
|
||||||
const [ groupedByDate, setGroupedByDate ] = useState<Map<String, RecentChangesRow[]>>();
|
const [ groupedByDate, setGroupedByDate ] = useState<Map<String, RecentChangeRow[]>>();
|
||||||
const [ needsRefresh, setNeedsRefresh ] = useState(false);
|
const [ needsRefresh, setNeedsRefresh ] = useState(false);
|
||||||
const [ shown, setShown ] = useState(false);
|
const [ shown, setShown ] = useState(false);
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ function RecentChangesDialogComponent() {
|
|||||||
setNeedsRefresh(false);
|
setNeedsRefresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.get<RecentChangesRow[]>(`recent-changes/${ancestorNoteId}`)
|
server.get<RecentChangeRow[]>(`recent-changes/${ancestorNoteId}`)
|
||||||
.then(async (recentChanges) => {
|
.then(async (recentChanges) => {
|
||||||
// preload all notes into cache
|
// preload all notes into cache
|
||||||
await froca.getNotes(
|
await froca.getNotes(
|
||||||
@ -78,7 +78,7 @@ function RecentChangesDialogComponent() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Map<String, RecentChangesRow[]>, setShown: Dispatch<StateUpdater<boolean>> }) {
|
function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Map<String, RecentChangeRow[]>, setShown: Dispatch<StateUpdater<boolean>> }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{ Array.from(groupedByDate.entries()).map(([dateDay, dayChanges]) => {
|
{ Array.from(groupedByDate.entries()).map(([dateDay, dayChanges]) => {
|
||||||
@ -129,7 +129,7 @@ function NoteLink({ notePath, title }: { notePath: string, title: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DeletedNoteLink({ change, setShown }: { change: RecentChangesRow, setShown: Dispatch<StateUpdater<boolean>> }) {
|
function DeletedNoteLink({ change, setShown }: { change: RecentChangeRow, setShown: Dispatch<StateUpdater<boolean>> }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<span className="note-title">{change.current_title}</span>
|
<span className="note-title">{change.current_title}</span>
|
||||||
@ -165,8 +165,8 @@ export default class RecentChangesDialog extends ReactBasicWidget {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function groupByDate(rows: RecentChangesRow[]) {
|
function groupByDate(rows: RecentChangeRow[]) {
|
||||||
const groupedByDate = new Map<String, RecentChangesRow[]>();
|
const groupedByDate = new Map<String, RecentChangeRow[]>();
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const dateDay = row.date.substr(0, 10);
|
const dateDay = row.date.substr(0, 10);
|
||||||
|
@ -9,8 +9,8 @@ interface DropdownProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Dropdown({ className, isStatic, children }: DropdownProps) {
|
export default function Dropdown({ className, isStatic, children }: DropdownProps) {
|
||||||
const dropdownRef = useRef<HTMLDivElement>();
|
const dropdownRef = useRef<HTMLDivElement | null>(null);
|
||||||
const triggerRef = useRef<HTMLButtonElement>();
|
const triggerRef = useRef<HTMLButtonElement | null>(null);
|
||||||
|
|
||||||
if (triggerRef?.current) {
|
if (triggerRef?.current) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -9,7 +9,7 @@ interface NoteAutocompleteProps {
|
|||||||
inputRef?: RefObject<HTMLInputElement>;
|
inputRef?: RefObject<HTMLInputElement>;
|
||||||
text?: string;
|
text?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
container?: RefObject<HTMLDivElement>;
|
container?: RefObject<HTMLElement | null | undefined>;
|
||||||
containerStyle?: CSSProperties;
|
containerStyle?: CSSProperties;
|
||||||
opts?: Omit<Options, "container">;
|
opts?: Omit<Options, "container">;
|
||||||
onChange?: (suggestion: Suggestion | null) => void;
|
onChange?: (suggestion: Suggestion | null) => void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user