From 52ecd797368cb7efedf66844001c505a5e76e2d0 Mon Sep 17 00:00:00 2001 From: Phil Date: Fri, 16 Sep 2022 16:43:49 +0100 Subject: [PATCH] Twitch prerelease (#887) * Bot linking button functional. * Implemented initial prototype of new Twitch signup page. * Removed old Twitch signup page. * Moved new Twitch page to correct URL. * Twitch account linking functional. * Fixed charity link. * Changed to point to live bot server. * Slightly improve spacing and alignment on Twitch page * Tidy up, handle some errors when talking to bot * Seriously do the thing where Twitch link is hidden by default * Fixed secondary Get Started button. Copy overlay and dock link now functional. * Add/remove bot from channel working. * Removed legacy Twitch controls from user profile. * Links provided by dock/overlay buttons are now correct. * Minor profile cleanup post merge. * Fixed unnecessary relinking Twitch account when logging in on Twitch page. * Added confirmation popup to refresh API key. Refreshing API key now requires a user to relink their Twitch account. * Removed legacy twitch-panel.tsx Co-authored-by: Marshall Polaris --- common/user.ts | 1 + web/components/profile/twitch-panel.tsx | 184 -------------- web/lib/twitch/link-twitch-account.ts | 11 + web/pages/profile.tsx | 79 ++++-- web/pages/twitch.tsx | 303 ++++++++++++++++-------- 5 files changed, 271 insertions(+), 307 deletions(-) delete mode 100644 web/components/profile/twitch-panel.tsx diff --git a/common/user.ts b/common/user.ts index b490ab0c..5ab07d35 100644 --- a/common/user.ts +++ b/common/user.ts @@ -71,6 +71,7 @@ export type PrivateUser = { twitchName: string controlToken: string botEnabled?: boolean + needsRelinking?: boolean } } diff --git a/web/components/profile/twitch-panel.tsx b/web/components/profile/twitch-panel.tsx deleted file mode 100644 index a37b21dc..00000000 --- a/web/components/profile/twitch-panel.tsx +++ /dev/null @@ -1,184 +0,0 @@ -import clsx from 'clsx' -import { MouseEventHandler, ReactNode, useState } from 'react' -import toast from 'react-hot-toast' - -import { LinkIcon } from '@heroicons/react/solid' -import { usePrivateUser, useUser } from 'web/hooks/use-user' -import { updatePrivateUser } from 'web/lib/firebase/users' -import { track } from 'web/lib/service/analytics' -import { - linkTwitchAccountRedirect, - updateBotEnabledForUser, -} from 'web/lib/twitch/link-twitch-account' -import { copyToClipboard } from 'web/lib/util/copy' -import { Button, ColorType } from './../button' -import { Row } from './../layout/row' -import { LoadingIndicator } from './../loading-indicator' -import { PrivateUser } from 'common/user' - -function BouncyButton(props: { - children: ReactNode - onClick?: MouseEventHandler - color?: ColorType - className?: string -}) { - const { children, onClick, color, className } = props - return ( - - ) -} - -function BotConnectButton(props: { - privateUser: PrivateUser | null | undefined -}) { - const { privateUser } = props - const [loading, setLoading] = useState(false) - - const updateBotConnected = (connected: boolean) => async () => { - if (!privateUser) return - const twitchInfo = privateUser.twitchInfo - if (!twitchInfo) return - - const error = connected - ? 'Failed to add bot to your channel' - : 'Failed to remove bot from your channel' - const success = connected - ? 'Added bot to your channel' - : 'Removed bot from your channel' - - setLoading(true) - toast.promise( - updateBotEnabledForUser(privateUser, connected).then(() => - updatePrivateUser(privateUser.id, { - twitchInfo: { ...twitchInfo, botEnabled: connected }, - }) - ), - { loading: 'Updating bot settings...', error, success } - ) - try { - } finally { - setLoading(false) - } - } - - return ( - <> - {privateUser?.twitchInfo?.botEnabled ? ( - - Remove bot from your channel - - ) : ( - - Add bot to your channel - - )} - - ) -} - -export function TwitchPanel() { - const user = useUser() - const privateUser = usePrivateUser() - - const twitchInfo = privateUser?.twitchInfo - const twitchName = twitchInfo?.twitchName - const twitchToken = twitchInfo?.controlToken - - const linkIcon =