41 lines
No EOL
1.1 KiB
TypeScript
41 lines
No EOL
1.1 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { authorizedGet } from '../../api';
|
|
import { useAuthToken } from './use-auth-token';
|
|
|
|
type Prompt = {
|
|
id: string;
|
|
user_id: string;
|
|
prompt_title: string;
|
|
workflow_manager_plan: string;
|
|
result: string;
|
|
created_at: string;
|
|
user_prompt: string;
|
|
};
|
|
|
|
export const useUserPrompts = () => {
|
|
const [prompts, setPrompts] = useState<Prompt[]>([]);
|
|
const [loading, setLoading] = useState<boolean>(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const { getToken } = useAuthToken();
|
|
|
|
const fetchPrompts = async () => {
|
|
setLoading(true);
|
|
setError(null);
|
|
try {
|
|
const response = await authorizedGet("/api/user/prompts", getToken);
|
|
setPrompts(response.data);
|
|
} catch (err) {
|
|
setError("Failed to fetch prompts");
|
|
console.error("Error fetching prompts:", err);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
fetchPrompts();
|
|
}, []);
|
|
|
|
return { prompts, loading, error, refetch: fetchPrompts };
|
|
};
|