File size: 1,052 Bytes
f8b5d42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useState, useEffect } from "react";
import CommunityHub from "@/models/communityHub";

const DEFAULT_USER_ITEMS = {
  createdByMe: {
    agentSkills: { items: [] },
    systemPrompts: { items: [] },
    slashCommands: { items: [] },
    agentFlows: { items: [] },
  },
  teamItems: [],
};

export function useUserItems({ connectionKey }) {
  const [loading, setLoading] = useState(true);
  const [userItems, setUserItems] = useState(DEFAULT_USER_ITEMS);

  useEffect(() => {
    const fetchData = async () => {
      console.log("fetching user items", connectionKey);
      if (!connectionKey) return;
      setLoading(true);
      try {
        const { success, createdByMe, teamItems } =
          await CommunityHub.fetchUserItems();
        if (success) {
          setUserItems({ createdByMe, teamItems });
        }
      } catch (error) {
        console.error("Error fetching user items:", error);
      } finally {
        setLoading(false);
      }
    };

    fetchData();
  }, [connectionKey]);

  return { loading, userItems };
}