mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 14:26:42 +02:00
Projects included: - maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing) - manacore (Expo mobile + SvelteKit web + Astro landing) - manadeck (NestJS backend + Expo mobile + SvelteKit web) - memoro (Expo mobile + SvelteKit web + Astro landing) This commit preserves the current state before monorepo restructuring. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
No EOL
1.3 KiB
TypeScript
44 lines
No EOL
1.3 KiB
TypeScript
import { useState, useEffect, useCallback } from 'react';
|
|
import { Story } from '../types/Story';
|
|
import { useAuth } from '../src/contexts/AuthContext';
|
|
import { dataService } from '../src/utils/dataService';
|
|
|
|
export function useStories() {
|
|
const [allStories, setAllStories] = useState<Story[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const { user, isAuthenticated } = useAuth();
|
|
|
|
const fetchStories = useCallback(async () => {
|
|
setLoading(true);
|
|
setError(null);
|
|
|
|
if (!isAuthenticated || !user) {
|
|
setLoading(false);
|
|
setError('User not authenticated');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const stories = await dataService.getStories(true); // Include archived stories
|
|
setAllStories(stories);
|
|
setLoading(false);
|
|
} catch (error) {
|
|
console.error('Error fetching stories:', error);
|
|
setError(error instanceof Error ? error.message : 'Unknown error');
|
|
setLoading(false);
|
|
}
|
|
}, [isAuthenticated, user]);
|
|
|
|
useEffect(() => {
|
|
fetchStories();
|
|
}, [fetchStories]);
|
|
|
|
const getStoryById = (id: string) => allStories.find(story => story.id === id);
|
|
|
|
const refreshStories = useCallback(async () => {
|
|
await fetchStories();
|
|
}, [fetchStories]);
|
|
|
|
return { allStories, getStoryById, loading, error, refreshStories };
|
|
} |