forked from Mastodon/mastoradio-la-radio-di-mastodon
add routing
This commit is contained in:
parent
3fb9b6e240
commit
307331855d
|
@ -8670,6 +8670,11 @@
|
|||
"integrity": "sha1-fRh9tcbNu9ZNdaMvkbiZi94yc8M=",
|
||||
"dev": true
|
||||
},
|
||||
"svelte-routing": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/svelte-routing/-/svelte-routing-1.4.0.tgz",
|
||||
"integrity": "sha512-09ypn0/vD2PcuyZEEocUHFgi7kvLOxSoUUuJZ4j3p4Y4sT/kMIWtHIRpnLdsr8bQ+sGo77sbEkO+av6yd1RjPg=="
|
||||
},
|
||||
"svgo": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/svgo/-/svgo-1.3.2.tgz",
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
"core-js-pure": "^3.6.4",
|
||||
"date-fns": "^2.9.0",
|
||||
"get-urls": "^9.2.0",
|
||||
"iter-tools": "^7.0.0-rc.0"
|
||||
"iter-tools": "^7.0.0-rc.0",
|
||||
"svelte-routing": "^1.4.0"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
|
|
|
@ -1,92 +1,10 @@
|
|||
<svelte:head>
|
||||
<title>{`${ $current ? `${$current.metadata.title} ∴ ` : ''}Eldritch Radio`}</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="app container">
|
||||
<Header></Header>
|
||||
|
||||
<section class="viewer">
|
||||
{#if $current}
|
||||
<Viewer></Viewer>
|
||||
<Controls></Controls>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="queue">
|
||||
<Queue></Queue>
|
||||
</section>
|
||||
|
||||
<Footer></Footer>
|
||||
</div>
|
||||
|
||||
<Router>
|
||||
<Route path="/share/:domain/:statusId" component={Share} />
|
||||
<Route path="/" component={Home} />
|
||||
</Router>
|
||||
|
||||
<script>
|
||||
|
||||
import { onMount, onDestroy } from 'svelte'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
import Header from '/components/layout/Header.svelte'
|
||||
import Footer from '/components/layout/Footer.svelte'
|
||||
import Controls from '/components/Controls.svelte'
|
||||
import Queue from '/components/Queue.svelte'
|
||||
import Viewer from '/components/Viewer.svelte'
|
||||
import { hashtagIterator, combinedIterator } from '/services/mastodon.js'
|
||||
import { mkTracksIterator } from '/services/misc.js'
|
||||
|
||||
import { domain, hashtags, queue, next, current, enqueueing, select } from '/store.js'
|
||||
|
||||
let nextUnsubcribe = null
|
||||
let currentUnsubcribe = null
|
||||
|
||||
onMount(async () => {
|
||||
// const iterator = mkTracksIterator(hashtagIterator(get(domain), get(hashtags)[0]))
|
||||
const domainValue = get(domain)
|
||||
const hashtagsValue = get(hashtags)
|
||||
|
||||
const iterator = combinedIterator(
|
||||
hashtagsValue.map(hashtag => mkTracksIterator(hashtagIterator(domainValue, hashtag)))
|
||||
)
|
||||
|
||||
const { value: first } = await iterator.next()
|
||||
|
||||
queue.set([first])
|
||||
select(first)
|
||||
|
||||
nextUnsubcribe = next.subscribe(async nextValue => {
|
||||
if (nextValue === null) {
|
||||
if (!get(enqueueing)) {
|
||||
enqueueing.set(true)
|
||||
|
||||
const { value: newTrack } = await iterator.next()
|
||||
|
||||
if (newTrack) {
|
||||
queue.update(queueValue => [...queueValue, newTrack])
|
||||
next.set(newTrack)
|
||||
}
|
||||
|
||||
enqueueing.set(false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
currentUnsubcribe = current.subscribe(currentValue => {
|
||||
if (currentValue !== null) {
|
||||
next.update(nextValue => {
|
||||
if (nextValue === currentValue) {
|
||||
return null
|
||||
} else {
|
||||
return nextValue
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
for (const unsubcribe of [nextUnsubcribe, currentUnsubcribe]) {
|
||||
if (unsubcribe) {
|
||||
unsubcribe()
|
||||
}
|
||||
}
|
||||
})
|
||||
import { Router, Route } from 'svelte-routing'
|
||||
import Home from '/routes/Home.svelte'
|
||||
import Share from '/routes/Share.svelte'
|
||||
</script>
|
|
@ -0,0 +1,90 @@
|
|||
<svelte:head>
|
||||
<title>{`${ $current ? `${$current.metadata.title} ∴ ` : ''}Eldritch Radio`}</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="app container">
|
||||
<Header></Header>
|
||||
|
||||
<section class="viewer">
|
||||
{#if $current}
|
||||
<Viewer></Viewer>
|
||||
<Controls></Controls>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="queue">
|
||||
<Queue></Queue>
|
||||
</section>
|
||||
|
||||
<Footer></Footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
import Header from '/components/layout/Header.svelte'
|
||||
import Footer from '/components/layout/Footer.svelte'
|
||||
import Controls from '/components/Controls.svelte'
|
||||
import Queue from '/components/Queue.svelte'
|
||||
import Viewer from '/components/Viewer.svelte'
|
||||
import { hashtagIterator, combinedIterator } from '/services/mastodon.js'
|
||||
import { mkTracksIterator } from '/services/misc.js'
|
||||
|
||||
import { domain, hashtags, queue, next, current, enqueueing, select } from '/store.js'
|
||||
|
||||
let nextUnsubcribe = null
|
||||
let currentUnsubcribe = null
|
||||
|
||||
onMount(async () => {
|
||||
// const iterator = mkTracksIterator(hashtagIterator(get(domain), get(hashtags)[0]))
|
||||
const domainValue = get(domain)
|
||||
const hashtagsValue = get(hashtags)
|
||||
|
||||
const iterator = combinedIterator(
|
||||
hashtagsValue.map(hashtag => mkTracksIterator(hashtagIterator(domainValue, hashtag)))
|
||||
)
|
||||
|
||||
const { value: first } = await iterator.next()
|
||||
|
||||
queue.set([first])
|
||||
select(first)
|
||||
|
||||
nextUnsubcribe = next.subscribe(async nextValue => {
|
||||
if (nextValue === null) {
|
||||
if (!get(enqueueing)) {
|
||||
enqueueing.set(true)
|
||||
|
||||
const { value: newTrack } = await iterator.next()
|
||||
|
||||
if (newTrack) {
|
||||
queue.update(queueValue => [...queueValue, newTrack])
|
||||
next.set(newTrack)
|
||||
}
|
||||
|
||||
enqueueing.set(false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
currentUnsubcribe = current.subscribe(currentValue => {
|
||||
if (currentValue !== null) {
|
||||
next.update(nextValue => {
|
||||
if (nextValue === currentValue) {
|
||||
return null
|
||||
} else {
|
||||
return nextValue
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
for (const unsubcribe of [nextUnsubcribe, currentUnsubcribe]) {
|
||||
if (unsubcribe) {
|
||||
unsubcribe()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
|
@ -0,0 +1,5 @@
|
|||
<Radio />
|
||||
|
||||
<script>
|
||||
import Radio from '/components/Radio.svelte'
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<Radio />
|
||||
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import Radio from '/components/Radio.svelte'
|
||||
import { fetchStatus } from '/services/mastodon.js'
|
||||
|
||||
export let domain
|
||||
export let statusId
|
||||
|
||||
|
||||
onMount(async () => {
|
||||
const status = await fetchStatus(domain, statusId)
|
||||
console.log(`Status ${statusId} from ${domain} shared`)
|
||||
})
|
||||
</script>
|
|
@ -3,6 +3,8 @@ import { observableToAsyncIterator } from '/services/misc.js'
|
|||
|
||||
const LINK_RE = /<(.+?)>; rel="(\w+)"/gi
|
||||
|
||||
export const fetchStatus = (domain, id) => fetch(`https://${domain}/api/v1/statuses/${id}`).then(x => x.json())
|
||||
|
||||
function parseLinkHeader(link) {
|
||||
const links = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue