Skip to content

Commit 6c08a8e

Browse files
author
Kevin Souza
committed
add twitch user from watch page, box art fix
1 parent 7ec7345 commit 6c08a8e

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/main/twitch/stream.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export async function fetchStreamInfo(username: string): Promise<StreamInfo> {
9696
const response = await fetch(box_art_url)
9797
if (response.redirected) {
9898
box_art = `https://static-cdn.jtvnw.net/ttv-boxart/${stream.game.id}_IGDB-144x192.jpg`
99+
} else if (response.status === 200) {
100+
box_art = box_art_url
99101
}
100102
} catch (err) {
101103
console.error(`Error fetching box art: ${err}`)

src/renderer/src/pages/streams/Watch.svelte

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import TwitchPlayer from '$lib/components/players/Twitch.svelte'
55
import Chat from '$lib/components/Chat.svelte'
66
import { notify } from '$lib/components/Notification.svelte'
7+
import { Platform } from '$shared/enums'
78
89
let username = $state('')
910
let url = $state('')
1011
let streamInfo = $state() as StreamInfo
12+
let subscribed = $state(false)
1113
1214
let loading = $state(true)
1315
@@ -52,13 +54,38 @@
5254
return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
5355
}
5456
57+
async function handleSubscription() {
58+
try {
59+
if (subscribed) {
60+
const deleted = await window.user.remove(Platform.Twitch, username)
61+
notify(`Unsubscribed from ${deleted}`)
62+
subscribed = false
63+
} else {
64+
const deleted = await window.user.add(Platform.Twitch, username)
65+
notify(`Subscribed to ${deleted}`)
66+
subscribed = true
67+
}
68+
} catch (err) {
69+
notify('Error updating subscription', err)
70+
}
71+
}
72+
73+
async function getPossibleUser() {
74+
const user = await window.user.get(Platform.Twitch, username)
75+
if (user) {
76+
subscribed = true
77+
}
78+
}
79+
5580
onMount(async () => {
5681
const routeURL = new URL(window.location.href)
5782
username = routeURL.searchParams.get('username')!
5883
5984
try {
6085
const data = await window.stream.get(username, false)
6186
url = data
87+
88+
await getPossibleUser()
6289
} catch {
6390
notify('Stream not found')
6491
loading = false
@@ -146,6 +173,15 @@
146173
</span>
147174
</div>
148175

176+
<div class="flex">
177+
<button
178+
class="cursor-pointer border border-white/25 p-1 px-2 hover:bg-neutral-400/50"
179+
onclick={async () => await handleSubscription()}
180+
>
181+
{subscribed ? 'SUBSCRIBED' : 'SUBSCRIBE'}
182+
</button>
183+
</div>
184+
149185
<div class="flex items-center gap-2">
150186
<img src={streamInfo.box_art} alt={streamInfo.game} width={72} height={96} />
151187

src/renderer/src/pages/videos/Watch.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
subscribed = true
2828
}
2929
} catch (err) {
30-
notify(`Error subscribing to ${player.channel.name}`, err)
30+
notify('Error updating subscription', err)
3131
}
3232
}
3333
@@ -128,7 +128,7 @@
128128
</span>
129129

130130
<button
131-
class="cursor-pointer p-1 px-2 hover:bg-neutral-400/50"
131+
class="cursor-pointer border border-white/25 p-1 px-2 hover:bg-neutral-400/50"
132132
onclick={async () => await handleSubscription()}
133133
>
134134
{subscribed ? 'SUBSCRIBED' : 'SUBSCRIBE'}

0 commit comments

Comments
 (0)