"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 { getChannels } from "@/app/server/actions/ai-tube-hf/getChannels" import { ChannelList } from "@/app/interface/channel-list" import { localStorageKeys } from "@/app/state/locaStorageKeys" import { defaultSettings } from "@/app/state/defaultSettings" import { Input } from "@/components/ui/input" export function UserChannelsView() { const [_isPending, startTransition] = useTransition() const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage( localStorageKeys.huggingfaceApiKey, defaultSettings.huggingfaceApiKey ) const setView = useStore(s => s.setView) const setCurrentChannel = useStore(s => s.setCurrentChannel) const currentChannels = useStore(s => s.currentChannels) const setCurrentChannels = useStore(s => s.setCurrentChannels) const [isLoaded, setLoaded] = useState(false) useEffect(() => { if (!isLoaded) { startTransition(async () => { try { const channels = await getChannels({ apiKey: huggingfaceApiKey }) setCurrentChannels(channels) } catch (err) { console.error("failed to load the channel for the current user:", err) setCurrentChannels([]) } 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:

{currentChannels?.length ? { setCurrentChannel(channel) setView("user_channel") }} /> :

Ask @jbilcke-hf for help to create a channel!

}
: null}
) }