"use client" import { useEffect, useState, useTransition } from "react" import { useLocalStorage } from "usehooks-ts" import { useStore } from "@/app/state/useStore" import { cn } from "@/lib/utils" import { ChannelList } from "@/app/interface/channel-list" import { localStorageKeys } from "@/app/state/localStorageKeys" import { defaultSettings } from "@/app/state/defaultSettings" import { Input } from "@/components/ui/input" import { getPrivateChannels } from "@/app/server/actions/ai-tube-hf/getPrivateChannels" export function UserAccountView() { const [_isPending, startTransition] = useTransition() const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage( localStorageKeys.huggingfaceApiKey, defaultSettings.huggingfaceApiKey ) const setView = useStore(s => s.setView) const setUserChannel = useStore(s => s.setUserChannel) const userChannels = useStore(s => s.userChannels) const setUserChannels = useStore(s => s.setUserChannels) const [isLoaded, setLoaded] = useState(false) useEffect(() => { if (!isLoaded) { startTransition(async () => { try { const channels = await getPrivateChannels({ apiKey: huggingfaceApiKey, renewCache: true, }) setUserChannels(channels) } catch (err) { console.error("failed to load the channel for the current user:", err) setUserChannels([]) } finally { setLoaded(true) } }) } }, [isLoaded, huggingfaceApiKey]) return (

Want your own channels? Setup your account!

{ setHuggingfaceApiKey(x.target.value) }} value={huggingfaceApiKey} />

Note: your Hugging Face token must be a WRITE access token.

{huggingfaceApiKey ?

Nice, looks like you are ready to go!

:

Please setup your account (see above) to get started

}
{huggingfaceApiKey ?

Your custom channels:

{userChannels?.length ? { if (userChannel.id) { setUserChannel(userChannel) } setView("user_channel") }} /> : isLoaded ?

You don't seem to have any channel yet. See @flngr on X to learn more about how to do this!

:

Loading channels..

}
: null}
) }