mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
refactor(react): fix all eslint issues in .tsx files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { CKTextEditor, type AttributeEditor, type EditorConfig, type ModelPosition } from "@triliumnext/ckeditor5";
|
||||
import type { CKTextEditor, AttributeEditor, EditorConfig, ModelPosition } from "@triliumnext/ckeditor5";
|
||||
import { useEffect, useImperativeHandle, useRef } from "preact/compat";
|
||||
import { MutableRef } from "preact/hooks";
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ interface FormGroupProps {
|
||||
label?: string;
|
||||
title?: string;
|
||||
className?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
children: VNode<any>;
|
||||
description?: string | ComponentChildren;
|
||||
disabled?: boolean;
|
||||
|
||||
@@ -65,6 +65,7 @@ function FormSelectBody({ id, name, children, onChange, style, className }: { id
|
||||
return (
|
||||
<select
|
||||
id={id}
|
||||
name={name}
|
||||
onChange={e => onChange((e.target as HTMLInputElement).value)}
|
||||
style={style}
|
||||
className={`form-select ${className ?? ""}`}
|
||||
@@ -78,10 +79,10 @@ function FormSelectGroup<T>({ values, keyProperty, titleProperty, currentValue }
|
||||
return values.map(item => {
|
||||
return (
|
||||
<option
|
||||
value={item[keyProperty] as any}
|
||||
value={item[keyProperty] as string | number}
|
||||
selected={item[keyProperty] === currentValue}
|
||||
>
|
||||
{item[titleProperty ?? keyProperty] ?? item[keyProperty] as any}
|
||||
{item[titleProperty ?? keyProperty] ?? item[keyProperty] as string | number}
|
||||
</option>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { t } from "../../services/i18n";
|
||||
import { openInAppHelpFromUrl } from "../../services/utils";
|
||||
import "./FormToggle.css";
|
||||
import HelpButton from "./HelpButton";
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function KeyboardShortcut({ actionName }: KeyboardShortcutProps)
|
||||
|
||||
return (
|
||||
<>
|
||||
{action.effectiveShortcuts?.map((shortcut, i) => {
|
||||
{action.effectiveShortcuts?.map((shortcut) => {
|
||||
const keys = shortcut.split("+");
|
||||
return joinElements(keys
|
||||
.map((key, i) => (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import link from "../../services/link";
|
||||
import RawHtml from "./RawHtml";
|
||||
|
||||
|
||||
@@ -16,16 +16,16 @@ import { Tooltip } from "bootstrap";
|
||||
import { CSSProperties } from "preact/compat";
|
||||
|
||||
export function useTriliumEvent<T extends EventNames>(eventName: T, handler: (data: EventData<T>) => void) {
|
||||
const parentComponent = useContext(ParentComponent)!;
|
||||
const parentComponent = useContext(ParentComponent);
|
||||
useEffect(() => {
|
||||
parentComponent.registerHandler(eventName, handler);
|
||||
return (() => parentComponent.removeHandler(eventName, handler));
|
||||
parentComponent?.registerHandler(eventName, handler);
|
||||
return (() => parentComponent?.removeHandler(eventName, handler));
|
||||
}, [ eventName, handler ]);
|
||||
useDebugValue(eventName);
|
||||
}
|
||||
|
||||
export function useTriliumEvents<T extends EventNames>(eventNames: T[], handler: (data: EventData<T>, eventName: T) => void) {
|
||||
const parentComponent = useContext(ParentComponent)!;
|
||||
const parentComponent = useContext(ParentComponent);
|
||||
|
||||
useEffect(() => {
|
||||
const handlers: ({ eventName: T, callback: (data: EventData<T>) => void })[] = [];
|
||||
@@ -36,12 +36,12 @@ export function useTriliumEvents<T extends EventNames>(eventNames: T[], handler:
|
||||
}
|
||||
|
||||
for (const { eventName, callback } of handlers) {
|
||||
parentComponent.registerHandler(eventName, callback);
|
||||
parentComponent?.registerHandler(eventName, callback);
|
||||
}
|
||||
|
||||
return (() => {
|
||||
for (const { eventName, callback } of handlers) {
|
||||
parentComponent.removeHandler(eventName, callback);
|
||||
parentComponent?.removeHandler(eventName, callback);
|
||||
}
|
||||
});
|
||||
}, [ eventNames, handler ]);
|
||||
@@ -209,7 +209,7 @@ export function useNoteContext() {
|
||||
useTriliumEvent("noteSwitchedAndActivated", ({ noteContext }) => {
|
||||
setNoteContext(noteContext);
|
||||
});
|
||||
useTriliumEvent("noteSwitched", ({ noteContext, notePath }) => {
|
||||
useTriliumEvent("noteSwitched", ({ notePath }) => {
|
||||
setNotePath(notePath);
|
||||
});
|
||||
useTriliumEvent("frocaReloaded", () => {
|
||||
@@ -253,7 +253,7 @@ export function useNoteProperty<T extends keyof FNote>(note: FNote | null | unde
|
||||
return null;
|
||||
}
|
||||
|
||||
const [ value, setValue ] = useState<FNote[T]>(note[property]);
|
||||
const [, setValue ] = useState<FNote[T]>(note[property]);
|
||||
const refreshValue = () => setValue(note[property]);
|
||||
|
||||
// Watch for note changes.
|
||||
@@ -513,13 +513,14 @@ export function useTooltip(elRef: RefObject<HTMLElement>, config: Partial<Toolti
|
||||
return { showTooltip, hideTooltip };
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
export function useLegacyImperativeHandlers(handlers: Record<string, Function>, force?: boolean) {
|
||||
const parentComponent = useContext(ParentComponent);
|
||||
if (!force) {
|
||||
useEffect(() => {
|
||||
Object.assign(parentComponent as any, handlers);
|
||||
Object.assign(parentComponent as never, handlers);
|
||||
}, [ handlers ])
|
||||
} else {
|
||||
Object.assign(parentComponent as any, handlers);
|
||||
Object.assign(parentComponent as never, handlers);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { ComponentChild, createContext, render, type JSX, type RefObject } from "preact";
|
||||
import Component from "../../components/component";
|
||||
import { EventData, EventNames } from "../../components/app_context";
|
||||
import { useContext } from "preact/hooks";
|
||||
|
||||
export const ParentComponent = createContext<Component | null>(null);
|
||||
|
||||
@@ -44,6 +42,13 @@ export function disposeReactWidget(container: Element) {
|
||||
}
|
||||
|
||||
export function joinElements(components: ComponentChild[], separator = ", ") {
|
||||
return components.reduce<any>((acc, item) =>
|
||||
(acc.length ? [...acc, separator, item] : [item]), []);
|
||||
const joinedComponents: ComponentChild[] = [];
|
||||
for (let i=0; i<components.length; i++) {
|
||||
joinedComponents.push(components[i]);
|
||||
if (i + 1 < components.length) {
|
||||
joinedComponents.push(separator);
|
||||
}
|
||||
}
|
||||
|
||||
return joinedComponents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user