-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (79 loc) · 3.04 KB
/
index.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>@radio4000/sdk</title>
<link rel="icon" href="data:;base64,ivborw0kggo=" />
</head>
<body>
<article>
<p>
Testing the <a href="https://github.com/radio4000/sdk">@radio4000/sdk</a>. Try it out in the browser console
under `window.sdk`.
</p>
</article>
<ul id="channels"></ul>
<script type="module">
// We can set up our own sdk, if we want.
// import {createClient} from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm'
// import {createSdk} from './src/main.js'
// const supabaseClient = createClient(
// 'https://myjhnqgfwqtcicnvcwcj.supabase.co',
// 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTY0MTQxNTQ3MiwiZXhwIjoxOTU2OTkxNDcyfQ.gySR3Lv-m_CIj2Eyx6kfyOdwwMXEOFOgeHSjADqcM4Y'
// )
// const sdk = createSdk(supabaseClient)
// Or we can use the one we provide as convenience.
import {sdk} from './src/main.js'
// For debugging
window.sdk = sdk
console.log('The sdk is now available under window.sdk')
// Fetch and render some channels to test.
const ul = document.querySelector('#channels')
sdk.channels.readChannels(100).then((response) => {
console.log(response)
if (!response?.data) {
return
}
for (const c of response.data) {
const li = document.createElement('li')
const input = document.createElement('input')
input.value = c.id
li.textContent = c.name + ' @' + c.slug
li.append(input)
ul.appendChild(li)
}
// Testing it worked
sdk.channels.readChannel(response.data[0].slug).then((res) => console.log(res))
})
/**
* Tests a few SDK methods by running and chaining them. This should always work.
* Creates a new channel, queries it by slug, updates the name and validates it worked.
* For now you need to pass it a user email and password.
*
* @param {string} slug - a new, unique slug for the channel to be created
*/
async function sdkTest(slug, email, password) {
console.log('testing')
const {
data: {user},
} = await sdk.auth.signIn({email, password})
await sdk.channels.createChannel({name: 'Radio Test', slug: slug})
const {data: channel} = await sdk.channels.readChannel(slug)
await sdk.channels.updateChannel(channel.id, {name: 'updated'})
const {data: updatedChannel} = await sdk.channels.readChannel(slug)
console.log('same channel', channel.id === updatedChannel.id)
console.log('name field was updated', updatedChannel.name === 'updated')
const {data: track} = await sdk.tracks.createTrack(channel.id, {
url: 'https://www.youtube.com/watch?v=dA55o_18a-g',
title: 'My new track',
})
console.log('track was created', track.title === 'My new track')
// @todo delete the channel and track + user
//await sdk.channels.delete(channel.id)
}
window.sdkTest = sdkTest
</script>
<p>See the <a href="/docs">full documentation</a>.</p>
</body>
</html>