From 10e6938b117e850e3a629596568989397e5d146f Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Mon, 14 Nov 2022 09:28:46 +0300 Subject: [PATCH] tracker-script --- src/components/Article/AudioPlayer.tsx | 74 +++++++++++++++++++++ src/components/Article/FullArticle.tsx | 12 ++++ src/components/Article/MusicPlayer.tsx | 9 --- src/graphql/query/article-by-slug.ts | 2 + src/graphql/types.gen.ts | 3 +- src/utils/soundwave.ts | 92 ++++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 10 deletions(-) create mode 100644 src/components/Article/AudioPlayer.tsx delete mode 100644 src/components/Article/MusicPlayer.tsx create mode 100644 src/utils/soundwave.ts diff --git a/src/components/Article/AudioPlayer.tsx b/src/components/Article/AudioPlayer.tsx new file mode 100644 index 00000000..b7f2336f --- /dev/null +++ b/src/components/Article/AudioPlayer.tsx @@ -0,0 +1,74 @@ +import { createMemo, createSignal, onMount } from 'solid-js' +import { For } from 'solid-js/web' +import type { Shout } from '../../graphql/types.gen' +import { drawAudio } from '../../utils/soundwave' +type MediaItem = any + +export default (props: { shout: Shout }) => { + const media = createMemo(() => { + if (props.shout.media) { + console.debug(props.shout.media) + return [...JSON.parse(props.shout.media)] + } + return [] + }) + const [currentTrack, setCurrentTrack] = createSignal(media()[0]) + const [paused, setPaused] = createSignal(true) + const togglePlayPause = () => setPaused(!paused()) + const playMedia = (m: MediaItem) => {} + const [audioContext, setAudioContext] = createSignal() + const currentTimer = createMemo(() => { + // TODO: return current audio player track position + return 1 + }) + + onMount(() => { + const actx = new AudioContext() + setAudioContext(actx) + drawAudio(actx, currentTrack().src) + }) + + const SoundWave = () => + return ( +
+
+ {props.shout.title} +
+ +
+
+
{currentTrack().title}
+ +
+ + {currentTimer() / currentTrack().length} +
+
+ +
    + + {(m: MediaItem) => ( +
  • +
    + playMedia(m)}> +
    + {m.title} +
  • + )} +
    +
+
+
+ ) +} diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index ab6d6b07..c516872b 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -65,8 +65,20 @@ export const FullArticle = (props: ArticleProps) => { }) } } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const script = document.createElement('script') + script.type = 'text/javascript' + script.src = 'https://ackee.discours.io/tracker.js' + script.setAttribute('data-ackee-domain-id', 'dfaf6bc4-163c-4885-9d8b-1e72f7064d42') + script.setAttribute('data-ackee-server', 'https://ackee.discours.io') + script.async = true + document.head.appendChild(script) }) + //