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 | "use client"; |
| #2 | |
| #3 | import { Button } from "@/components/ui/button"; |
| #4 | import { |
| #5 | Dialog, |
| #6 | DialogContent, |
| #7 | DialogDescription, |
| #8 | DialogFooter, |
| #9 | DialogHeader, |
| #10 | DialogTitle, |
| #11 | } from "@/components/ui/dialog"; |
| #12 | import { Label } from "@/components/ui/label"; |
| #13 | import { useRef } from "react"; |
| #14 | import { Loader2 } from "lucide-react"; |
| #15 | import { useMemoriesApi } from "@/hooks/useMemoriesApi"; |
| #16 | import { toast } from "sonner"; |
| #17 | import { Textarea } from "@/components/ui/textarea"; |
| #18 | import { usePathname } from "next/navigation"; |
| #19 | |
| #20 | interface UpdateMemoryProps { |
| #21 | memoryId: string; |
| #22 | memoryContent: string; |
| #23 | open: boolean; |
| #24 | onOpenChange: (open: boolean) => void; |
| #25 | } |
| #26 | |
| #27 | const UpdateMemory = ({ |
| #28 | memoryId, |
| #29 | memoryContent, |
| #30 | open, |
| #31 | onOpenChange, |
| #32 | }: UpdateMemoryProps) => { |
| #33 | const { updateMemory, isLoading, fetchMemories, fetchMemoryById } = |
| #34 | useMemoriesApi(); |
| #35 | const textRef = useRef<HTMLTextAreaElement>(null); |
| #36 | const pathname = usePathname(); |
| #37 | |
| #38 | const handleUpdateMemory = async (text: string) => { |
| #39 | try { |
| #40 | await updateMemory(memoryId, text); |
| #41 | toast.success("Memory updated successfully"); |
| #42 | onOpenChange(false); |
| #43 | if (pathname.includes("memories")) { |
| #44 | await fetchMemories(); |
| #45 | } else { |
| #46 | await fetchMemoryById(memoryId); |
| #47 | } |
| #48 | } catch (error) { |
| #49 | console.error(error); |
| #50 | toast.error("Failed to update memory"); |
| #51 | } |
| #52 | }; |
| #53 | |
| #54 | return ( |
| #55 | <Dialog open={open} onOpenChange={onOpenChange}> |
| #56 | <DialogContent className="sm:max-w-[525px] bg-zinc-900 border-zinc-800 z-50"> |
| #57 | <DialogHeader> |
| #58 | <DialogTitle>Update Memory</DialogTitle> |
| #59 | <DialogDescription>Edit your existing memory</DialogDescription> |
| #60 | </DialogHeader> |
| #61 | <div className="grid gap-4 py-4"> |
| #62 | <div className="grid gap-2"> |
| #63 | <Label htmlFor="memory">Memory</Label> |
| #64 | <Textarea |
| #65 | ref={textRef} |
| #66 | id="memory" |
| #67 | className="bg-zinc-950 border-zinc-800 min-h-[150px]" |
| #68 | defaultValue={memoryContent} |
| #69 | /> |
| #70 | </div> |
| #71 | </div> |
| #72 | <DialogFooter> |
| #73 | <Button variant="outline" onClick={() => onOpenChange(false)}> |
| #74 | Cancel |
| #75 | </Button> |
| #76 | <Button |
| #77 | className="w-[140px]" |
| #78 | disabled={isLoading} |
| #79 | onClick={() => handleUpdateMemory(textRef?.current?.value || "")} |
| #80 | > |
| #81 | {isLoading ? ( |
| #82 | <Loader2 className="w-4 h-4 mr-2 animate-spin" /> |
| #83 | ) : ( |
| #84 | "Update Memory" |
| #85 | )} |
| #86 | </Button> |
| #87 | </DialogFooter> |
| #88 | </DialogContent> |
| #89 | </Dialog> |
| #90 | ); |
| #91 | }; |
| #92 | |
| #93 | export default UpdateMemory; |
| #94 |