managarten/picture/apps/mobile/hooks/useImageLikes.ts
Till-JS c712a2504a feat: integrate uload and picture, unify package naming
- Add uload project with apps/web structure
  - Reorganize from flat to monorepo structure
  - Remove PocketBase binary and local data
  - Update to pnpm and @uload/web namespace

- Add picture project to monorepo
  - Remove embedded git repository

- Unify all package names to @{project}/{app} schema:
  - @maerchenzauber/* (was @storyteller/*)
  - @manacore/* (was manacore-*, manacore)
  - @manadeck/* (was web, backend, manadeck)
  - @memoro/* (was memoro-web, landing, memoro)
  - @picture/* (already unified)
  - @uload/web

- Add convenient dev scripts for all apps:
  - pnpm dev:{project}:web
  - pnpm dev:{project}:landing
  - pnpm dev:{project}:mobile
  - pnpm dev:{project}:backend

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 04:00:36 +01:00

56 lines
1.3 KiB
TypeScript

import { supabase } from '~/utils/supabase';
import { router } from 'expo-router';
import { ExploreImageItem } from '~/types/explore';
type UseImageLikesProps = {
userId: string | undefined;
items: ExploreImageItem[];
setItems: (items: ExploreImageItem[]) => void;
onError?: (error: Error) => void;
};
export function useImageLikes({ userId, items, setItems, onError }: UseImageLikesProps) {
const toggleLike = async (imageId: string, userHasLiked: boolean) => {
if (!userId) {
router.push('/login');
return;
}
try {
if (userHasLiked) {
// Unlike
await supabase
.from('image_likes')
.delete()
.eq('image_id', imageId)
.eq('user_id', userId);
} else {
// Like
await supabase
.from('image_likes')
.insert({
image_id: imageId,
user_id: userId
});
}
// Update local state
setItems(items.map(img =>
img.id === imageId
? {
...img,
user_has_liked: !userHasLiked,
likes_count: (img.likes_count || 0) + (userHasLiked ? -1 : 1)
}
: img
));
} catch (error) {
console.error('Error toggling like:', error);
onError?.(error as Error);
}
};
return {
toggleLike,
};
}