diff --git a/app/api_routes.py b/app/api_routes.py index 1372c59..e375463 100644 --- a/app/api_routes.py +++ b/app/api_routes.py @@ -267,9 +267,7 @@ def api_delete_chatbot(chatbot_id: int) -> Union[Response, tuple[Response, int]] db.session.commit() return ( - jsonify( - {"message": f"Chatbot '{chatbot.id}' has been deleted successfully."} - ), + jsonify({"message": f"Chatbot '{chatbot.id}' has been deleted successfully."}), 200, ) @@ -560,6 +558,7 @@ def api_get_data(): "user_bots", "trend_today", "leaderboard", + "user_images", } queues = [q for q in queues if q in valid_queues] response = {"success": True} @@ -593,6 +592,9 @@ def api_get_data(): Chatbot.user_id == o_uid ).all() response["user_bots"] = [bot.to_dict() for bot in o_chatbots] + if "user_images" in queues: + o_images: List[Image] = Image.query.filter(Image.user_id == o_uid).all() + response["user_images"] = [image.to_dict() for image in o_images] if "trend_today" in queues: chatbot_of_the_day: Chatbot = ( diff --git a/client/bun.lockb b/client/bun.lockb index ca1da32..a846132 100755 Binary files a/client/bun.lockb and b/client/bun.lockb differ diff --git a/client/package.json b/client/package.json index c76c390..bdddee9 100644 --- a/client/package.json +++ b/client/package.json @@ -24,6 +24,7 @@ "@radix-ui/react-select": "^2.1.2", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.1", + "@radix-ui/react-tabs": "^1.1.1", "@tanstack/react-query": "^5.59.15", "axios": "^1.7.7", "class-variance-authority": "^0.7.0", diff --git a/client/src/components/ChatbotCard.tsx b/client/src/components/ChatbotCard.tsx index 3d77f00..f56c1de 100644 --- a/client/src/components/ChatbotCard.tsx +++ b/client/src/components/ChatbotCard.tsx @@ -1,12 +1,11 @@ import { Flag, Heart, MessageSquare, Share2, Trash2 } from "lucide-react"; // Import the Trash icon -import { useShareModal } from "@/stores/modal-store"; +import { useDeleteChatbotModal, useShareModal } from "@/stores/modal-store"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { likeAndReport, deleteChatbot } from "@/lib/queries"; // Ensure you have a deleteChatbot function +import { likeAndReport } from "@/lib/queries"; // Ensure you have a deleteChatbot function import { Card, CardContent, CardFooter, CardHeader } from "./ui/card"; import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar"; import { Button } from "./ui/button"; import { Link, useNavigate } from "react-router-dom"; -import { toast } from "react-hot-toast"; // Optional for notifications export function ChatbotCard({ chatbot, @@ -18,31 +17,14 @@ export function ChatbotCard({ const shareModel = useShareModal(); const rq = useQueryClient(); const navigate = useNavigate(); - + const deleteModal = useDeleteChatbotModal(); const likeMutation = useMutation({ mutationFn: likeAndReport, onSuccess: () => rq.invalidateQueries({ queryKey: queryKeys }), }); - const deleteMutation = useMutation({ - mutationFn: deleteChatbot, // Your API function to delete a chatbot - onSuccess: () => { - rq.invalidateQueries({ queryKey: queryKeys }); - toast.success("Chatbot deleted successfully!"); // Notify the user - }, - onError: () => { - toast.error("Failed to delete the chatbot."); // Error handling - }, - }); - - const handleDelete = () => { - if (window.confirm("Are you sure you want to delete this chatbot?")) { - deleteMutation.mutate(String(chatbot.id)); // Convert to string - } - }; - return ( - + @@ -55,7 +37,9 @@ export function ChatbotCard({
-

{chatbot.latest_version.name}

+

+ {chatbot.latest_version.name} +

Created by @{chatbot.latest_version.modified_by}

@@ -134,7 +118,11 @@ export function ChatbotCard({
); diff --git a/client/src/pages/Profile.tsx b/client/src/pages/Profile.tsx index b876c8c..4f98377 100644 --- a/client/src/pages/Profile.tsx +++ b/client/src/pages/Profile.tsx @@ -14,6 +14,8 @@ import { LogOut, Settings, } from "lucide-react"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; + import { Navigate, useParams } from "react-router-dom"; import { useSettingsModal, useUpdateProfileModal } from "@/stores/modal-store"; import { ChatbotCard } from "@/components/ChatbotCard"; @@ -21,6 +23,7 @@ import moment from "moment"; import { Badge } from "@/components/ui/badge"; import { useEffect, useState } from "react"; import { Skeleton } from "@/components/ui/skeleton"; +import { ImageCard } from "@/components/ImageCard"; export default function ProfilePage() { const { username } = useParams(); @@ -59,6 +62,16 @@ export default function ProfilePage() { enabled: !!userId, }); + const { + data: imagesData, + isLoading: imagesLoading, + error: imagesError, + } = useQuery({ + queryKey: ["user_images"], + queryFn: () => fetchData({ queues: ["user_images"], uid: userId }), + enabled: !!userId, + }); + if (isError && (error as AxiosError).response?.status === 404) { return ; // Redirect to the 404 page } @@ -168,25 +181,52 @@ export default function ProfilePage() {
-
- {botsLoading ? ( - - ) : botsError ? ( -
- {botsError?.message} + + + Chatbots + Images + + +
+ {botsLoading ? ( + + ) : botsError ? ( +
+ {botsError?.message} +
+ ) : botsData && botsData.user_bots!.length > 0 ? ( + botsData.user_bots!.map((item) => ( + + )) + ) : ( +
No bots available.
+ )}
- ) : botsData && botsData.user_bots!.length > 0 ? ( - botsData.user_bots!.map((item) => ( - - )) - ) : ( -
No bots available.
- )} -
+ + +
+ {imagesLoading ? ( + + ) : imagesError ? ( +
+ {imagesError?.message} +
+ ) : imagesData && imagesData.user_images!.length > 0 ? ( + imagesData.user_images!.map((item) => ( + + )) + ) : ( +
+ No Images available. +
+ )} +
+
+
);