jbilcke-hf HF staff commited on
Commit
7b89082
1 Parent(s): b965e2b

fix for the custom channels

Browse files
src/app/views/user-account-view/index.tsx CHANGED
@@ -1,30 +1,50 @@
1
  "use client"
2
 
3
- import { useTransition } from "react"
4
  import { useLocalStorage } from "usehooks-ts"
5
 
 
6
  import { cn } from "@/lib/utils"
7
- import { Input } from "@/components/ui/input"
 
8
  import { localStorageKeys } from "@/app/state/localStorageKeys"
9
  import { defaultSettings } from "@/app/state/defaultSettings"
 
10
 
11
  export function UserAccountView() {
 
12
  const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage<string>(
13
  localStorageKeys.huggingfaceApiKey,
14
  defaultSettings.huggingfaceApiKey
15
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  return (
18
- <div className={cn(
19
- `flex flex-col space-y-4`
20
- )}>
21
- {/*
22
- <div className="flex flex-col space-y-2 max-w-4xl">
23
- <p>Do you want your model to be featured?</p>
24
- <p>If it's free and open-source, tell me about it, I might be able to add it!</p>
25
- </div>
26
- */}
27
- <div className="flex flex-col space-y-2 max-w-4xl">
28
  <div className="flex flex-row space-x-2 items-center">
29
  <label className="flex w-64">Hugging Face token:</label>
30
  <Input
@@ -40,13 +60,23 @@ export function UserAccountView() {
40
  <p className="text-neutral-100/70">
41
  Note: your Hugging Face token must be a <span className="font-bold font-mono text-yellow-300">WRITE</span> access token.
42
  </p>
 
 
 
43
  </div>
44
- {huggingfaceApiKey
45
- ? <><p>You are ready to go for the beta!</p>
46
- <p>Please contact HF user <span className="text-xs font-mono bg-neutral-600 rounded-lg py-1 px-1.5">@jbilcke-hf</span> to learn how to create your own channel!</p></>
47
- : <><p>This project is in beta, you will be invited to contact HF user <span className="text-xs font-mono bg-neutral-600 rounded-lg py-1 px-1.5">@jbilcke-hf</span> to get started.</p>
48
- <p>But you can already setup your account (see above) to get started.</p></>}
49
-
 
 
 
 
 
 
 
50
  </div>
51
  )
52
  }
 
1
  "use client"
2
 
3
+ import { useEffect, useState, useTransition } from "react"
4
  import { useLocalStorage } from "usehooks-ts"
5
 
6
+ import { useStore } from "@/app/state/useStore"
7
  import { cn } from "@/lib/utils"
8
+ import { getChannels } from "@/app/server/actions/ai-tube-hf/getChannels"
9
+ import { ChannelList } from "@/app/interface/channel-list"
10
  import { localStorageKeys } from "@/app/state/localStorageKeys"
11
  import { defaultSettings } from "@/app/state/defaultSettings"
12
+ import { Input } from "@/components/ui/input"
13
 
14
  export function UserAccountView() {
15
+ const [_isPending, startTransition] = useTransition()
16
  const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage<string>(
17
  localStorageKeys.huggingfaceApiKey,
18
  defaultSettings.huggingfaceApiKey
19
  )
20
+ const setView = useStore(s => s.setView)
21
+ const setCurrentChannel = useStore(s => s.setCurrentChannel)
22
+
23
+ const currentChannels = useStore(s => s.currentChannels)
24
+ const setCurrentChannels = useStore(s => s.setCurrentChannels)
25
+ const [isLoaded, setLoaded] = useState(false)
26
+
27
+ useEffect(() => {
28
+ if (!isLoaded) {
29
+ startTransition(async () => {
30
+ try {
31
+ const channels = await getChannels({ apiKey: huggingfaceApiKey })
32
+ setCurrentChannels(channels)
33
+ } catch (err) {
34
+ console.error("failed to load the channel for the current user:", err)
35
+ setCurrentChannels([])
36
+ } finally {
37
+ setLoaded(true)
38
+ }
39
+ })
40
+ }
41
+ }, [isLoaded, huggingfaceApiKey])
42
 
43
  return (
44
+ <div className={cn(`flex flex-col space-y-4`)}>
45
+ <h2 className="text-3xl font-bold">Want your own channels? Setup your account!</h2>
46
+
47
+ <div className="flex flex-col space-y-4 max-w-2xl">
 
 
 
 
 
 
48
  <div className="flex flex-row space-x-2 items-center">
49
  <label className="flex w-64">Hugging Face token:</label>
50
  <Input
 
60
  <p className="text-neutral-100/70">
61
  Note: your Hugging Face token must be a <span className="font-bold font-mono text-yellow-300">WRITE</span> access token.
62
  </p>
63
+ {huggingfaceApiKey
64
+ ? <p className="">Nice, looks like you are ready to go!</p>
65
+ : <p>Please setup your account (see above) to get started</p>}
66
  </div>
67
+
68
+ {huggingfaceApiKey ?
69
+ <div className="flex flex-col space-y-4">
70
+ <h2 className="text-3xl font-bold">Your custom channels:</h2>
71
+ {currentChannels?.length ? <ChannelList
72
+ layout="grid"
73
+ channels={currentChannels}
74
+ onSelect={(channel) => {
75
+ setCurrentChannel(channel)
76
+ setView("user_channel")
77
+ }}
78
+ /> : <p>Ask <span className="font-mono">@jbilcke-hf</span> for help to create a channel!</p>}
79
+ </div> : null}
80
  </div>
81
  )
82
  }