diff options
| author | darkuss <darkussdelta@gmail.com> | 2026-08-22 01:58:37 +0200 |
|---|---|---|
| committer | darkuss <darkussdelta@gmail.com> | 2026-08-22 01:58:37 +0200 |
| commit | 8f32fd58cafe677c07d9ed9fff84f6e255156d37 (patch) | |
| tree | a5de06ffb2c0a8b878c8a563ec8cee692efc98ac /src/desktop/link.tsx | |
| parent | 5ac62cc1a4d9a5f50ea26d5bc1afb0fbf95da23c (diff) | |
holy shit i'm finally done
Diffstat (limited to 'src/desktop/link.tsx')
| -rw-r--r-- | src/desktop/link.tsx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/desktop/link.tsx b/src/desktop/link.tsx new file mode 100644 index 0000000..6b31b9e --- /dev/null +++ b/src/desktop/link.tsx @@ -0,0 +1,62 @@ +import { useCallback } from "preact/hooks" +import { getTaskId, taskManager } from "."; +import { signal } from "@preact/signals"; +import { Address } from "$/apps/source"; +import { APP_REGISTRY } from "$/apps"; +import { ComponentChildren } from "preact"; + +export function Link(props: Link.Props) { + const onClick = useCallback((e: MouseEvent) => { + if (props.external) { + return + } + let app = APP_REGISTRY[props.type]; + if (app === undefined) { + console.error(`couldn't find app for file of type "${props.type}"`) + return + } + + taskManager.add({ + app, + source: signal({ + type: props.type, + link: new URL(props.link), + pixelated: props.pixelated + } as Address), + window: { + minimized: signal(false), + maximized: signal(false), + height: props.type === "link" ? "40vh" : undefined, + width: props.type === "link" ? "40vw" : undefined, + z: signal(taskManager.tasks.value.value.length) + }, + title: signal(undefined), + id: getTaskId(), + contentReady: signal(false), + sizingFinished: signal(false) + }) + e.preventDefault(); + }, []) + + const content = <a target="_blank" rel="noreferrer noopener" onClick={onClick} href={props.link}> + { props.children ?? props.link } + </a> + + if (props.type === "image" || props.type === "video" || props.type === "audio" || props.block) { + return <div class="link">{content}</div> + } else { + return content + } +} + +namespace Link { + export type Props = { + link: string, + alt?: string, + type: "video" | "image" | "link" | "audio", + block?: boolean, + pixelated?: boolean, + external?: boolean, + children?: ComponentChildren + } +} |
