summaryrefslogtreecommitdiff
path: root/src/apps/audio.tsx
blob: 45d87162fde068e9932d4b6930f91ace621d8f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Signal, useSignalEffect } from "@preact/signals"
import { Address } from "$/apps/source";
import { memo, Ref, useEffect } from "preact/compat";

const filenameRegex = /.*\/(.*)$/;

export const Audio = memo(function Audio({ source, title, contentReady }: Image.Props) {
    useEffect(() => {
        contentReady.value = true
    }, [])

    useSignalEffect(() => {
        const filename = decodeURIComponent(source.value.link.pathname.match(filenameRegex)?.[1] ?? source.value.link.toString());
        title.value = `${filename} - tunez player`;
    })


    return <audio controls src={source.value.link.toString()}></audio>
})

namespace Image {
    export type Props = {
        source: Signal<Address>,
        title: Signal<string | undefined>,
        contentReady: Signal<boolean>,
    }
}