diff --git a/src/App.tsx b/src/App.tsx
index 6b235e1..81d334b 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,18 +1,10 @@
-import {
- ChangeEventHandler, Dispatch,
- KeyboardEventHandler,
- MouseEventHandler,
- ReactNode, SetStateAction,
- useCallback,
- useEffect,
- useRef,
- useState
-} from "react";
+import {ReactNode, useCallback, useState} from "react";
import {FixedSizeList as List} from "react-window";
import Select, {createFilter, MenuListProps} from "react-select";
import * as R from 'ramda';
import {useQuery} from "@tanstack/react-query";
+import {Alias, CustomAlias, Option} from "./aliases";
// TODO: Fix this for wrapping items, esp on phones
const height = 35;
@@ -44,15 +36,6 @@ function MenuList(props: MenuListProps) {
);
}
-interface Option {
- label: string,
- value: string,
- data: {
- backlinks: unknown[]
- aliases?: string[]
- }
-}
-
export function LargeSelect() {
const {
data: options,
@@ -110,103 +93,3 @@ export function LargeSelect() {
)
}
-
-function CustomAlias({selected}: {
- selected: Option
-}) {
- const [alias, setAlias] = useState('');
-
- // Reset when selection changes
- useEffect(() => {
- setAlias('');
- }, [selected.value]);
-
- const onClick: MouseEventHandler = useCallback((e) => {
- if ((e.target as HTMLElement).tagName == 'SPAN' && alias.length > 0) {
- navigator.clipboard.writeText(`[[${selected!.label}|${alias}]]`);
- }
- }, [selected.value, selected.label, alias]);
-
- return (
-
- [[
- {selected.label}
- |
-
-
-
- ]]
-
- )
-}
-
-function CustomAliasField({
- selected,
- content,
- setContent
- }: {
- selected: Option,
- content: string,
- setContent: Dispatch>,
-}) {
- const [width, setWidth] = useState(0);
- const span = useRef(null);
-
- // Resize on change of content
- useEffect(() => {
- setWidth(span.current!.offsetWidth);
- // setWidth(content.length + 'ch');
- }, [content]);
-
- const changeHandler: ChangeEventHandler = useCallback(evt => {
- setContent(evt.target.value);
- }, []);
-
- const onCustomElementKeyDown: KeyboardEventHandler = useCallback((e) => {
- if (e.key == 'Enter') {
- navigator.clipboard.writeText(`[[${selected!.label}|${content}]]`);
- (e.target as HTMLInputElement).blur()
- }
- }, [selected.value, selected.label, content]);
-
- return (
-
- {content}
-
-
- );
-}
-
-function Alias({
- original,
- alias
- }: {
- original: string,
- alias?: string
-}) {
- const onClick = useCallback(() => {
- if (alias) {
- navigator.clipboard.writeText(`[[${original}|${alias}]]`)
- } else {
- navigator.clipboard.writeText(`[[${original}]]`)
- }
- }, [original, alias]);
-
- return (
-
- [[
- {original}
- {alias && <>|
- {alias}>}
- ]]
-
- );
-}
diff --git a/src/aliases.tsx b/src/aliases.tsx
new file mode 100644
index 0000000..2215e48
--- /dev/null
+++ b/src/aliases.tsx
@@ -0,0 +1,120 @@
+import {
+ ChangeEventHandler,
+ Dispatch,
+ KeyboardEventHandler,
+ MouseEventHandler,
+ SetStateAction,
+ useCallback,
+ useEffect,
+ useRef,
+ useState
+} from "react";
+
+export interface Option {
+ label: string,
+ value: string,
+ data: {
+ backlinks: unknown[]
+ aliases?: string[]
+ }
+}
+
+export function CustomAlias({selected}: {
+ selected: Option
+}) {
+ const [alias, setAlias] = useState('');
+
+ // Reset when selection changes
+ useEffect(() => {
+ setAlias('');
+ }, [selected.value]);
+
+ const onClick: MouseEventHandler = useCallback((e) => {
+ if ((e.target as HTMLElement).tagName == 'SPAN' && alias.length > 0) {
+ navigator.clipboard.writeText(`[[${selected!.label}|${alias}]]`);
+ }
+ }, [selected.value, selected.label, alias]);
+
+ return (
+
+ [[
+ {selected.label}
+ |
+
+
+
+ ]]
+
+ )
+}
+
+function CustomAliasField({
+ selected,
+ content,
+ setContent
+ }: {
+ selected: Option,
+ content: string,
+ setContent: Dispatch>,
+}) {
+ const [width, setWidth] = useState(0);
+ const span = useRef(null);
+
+ // Resize on change of content
+ useEffect(() => {
+ setWidth(span.current!.offsetWidth);
+ // setWidth(content.length + 'ch');
+ }, [content]);
+
+ const changeHandler: ChangeEventHandler = useCallback(evt => {
+ setContent(evt.target.value);
+ }, []);
+
+ const onCustomElementKeyDown: KeyboardEventHandler = useCallback((e) => {
+ if (e.key == 'Enter') {
+ navigator.clipboard.writeText(`[[${selected!.label}|${content}]]`);
+ (e.target as HTMLInputElement).blur()
+ }
+ }, [selected.value, selected.label, content]);
+
+ return (
+
+ {content}
+
+
+ );
+}
+
+export function Alias({
+ original,
+ alias
+ }: {
+ original: string,
+ alias?: string
+}) {
+ const onClick = useCallback(() => {
+ if (alias) {
+ navigator.clipboard.writeText(`[[${original}|${alias}]]`)
+ } else {
+ navigator.clipboard.writeText(`[[${original}]]`)
+ }
+ }, [original, alias]);
+
+ return (
+
+ [[
+ {original}
+ {alias && <>|
+ {alias}>}
+ ]]
+
+ );
+}