repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { useState } from 'react'; |
| #2 | import axios from 'axios'; |
| #3 | import { useDispatch, useSelector } from 'react-redux'; |
| #4 | import { AppDispatch, RootState } from '@/store/store'; |
| #5 | import { setApps, setTotalApps } from '@/store/profileSlice'; |
| #6 | import { setTotalMemories } from '@/store/profileSlice'; |
| #7 | |
| #8 | // Define the new simplified memory type |
| #9 | export interface SimpleMemory { |
| #10 | id: string; |
| #11 | text: string; |
| #12 | created_at: string; |
| #13 | state: string; |
| #14 | categories: string[]; |
| #15 | app_name: string; |
| #16 | } |
| #17 | |
| #18 | // Define the shape of the API response item |
| #19 | interface APIStatsResponse { |
| #20 | total_memories: number; |
| #21 | total_apps: number; |
| #22 | apps: any[]; |
| #23 | } |
| #24 | |
| #25 | |
| #26 | interface UseMemoriesApiReturn { |
| #27 | fetchStats: () => Promise<void>; |
| #28 | isLoading: boolean; |
| #29 | error: string | null; |
| #30 | } |
| #31 | |
| #32 | export const useStats = (): UseMemoriesApiReturn => { |
| #33 | const [isLoading, setIsLoading] = useState<boolean>(false); |
| #34 | const [error, setError] = useState<string | null>(null); |
| #35 | const dispatch = useDispatch<AppDispatch>(); |
| #36 | const user_id = useSelector((state: RootState) => state.profile.userId); |
| #37 | |
| #38 | const URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8765"; |
| #39 | |
| #40 | const fetchStats = async () => { |
| #41 | setIsLoading(true); |
| #42 | setError(null); |
| #43 | try { |
| #44 | const response = await axios.get<APIStatsResponse>( |
| #45 | `${URL}/api/v1/stats?user_id=${user_id}` |
| #46 | ); |
| #47 | dispatch(setTotalMemories(response.data.total_memories)); |
| #48 | dispatch(setTotalApps(response.data.total_apps)); |
| #49 | dispatch(setApps(response.data.apps)); |
| #50 | } catch (err: any) { |
| #51 | const errorMessage = err.message || 'Failed to fetch stats'; |
| #52 | setError(errorMessage); |
| #53 | setIsLoading(false); |
| #54 | throw new Error(errorMessage); |
| #55 | } |
| #56 | }; |
| #57 | |
| #58 | return { fetchStats, isLoading, error }; |
| #59 | }; |