From 4dbee045fcf6967d68ba84ac4eb1bc92fab54d40 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:55:25 +0000 Subject: [PATCH] Refactor code The code has been refactored. --- src/components/panel/ConversationList.tsx | 12 +----------- src/components/panel/MessageComposer.tsx | 12 +----------- src/lib/supabase.ts | 11 +++++++++++ 3 files changed, 13 insertions(+), 22 deletions(-) create mode 100644 src/lib/supabase.ts diff --git a/src/components/panel/ConversationList.tsx b/src/components/panel/ConversationList.tsx index 2429689..d1e6925 100644 --- a/src/components/panel/ConversationList.tsx +++ b/src/components/panel/ConversationList.tsx @@ -3,19 +3,9 @@ import React from "react"; import { User } from "lucide-react"; import { Card } from "@/components/ui/card"; import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { createClient } from "@supabase/supabase-js"; +import { supabase } from "@/lib/supabase"; import { formatDistanceToNow } from "date-fns"; -// Initialize Supabase client -const supabaseUrl = "https://ikmbnngahzcellthaysf.supabase.co"; -const supabaseAnonKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlrbWJubmdhaHpjZWxsdGhheXNmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDA1ODY5NjUsImV4cCI6MjA1NjE2Mjk2NX0.puDSeLAaTirOPyj6ndF2Mzzu8CKxlwJsoFP6gK8cWuA"; - -if (!supabaseUrl || !supabaseAnonKey) { - throw new Error('Supabase URL and Anon Key are required'); -} - -const supabase = createClient(supabaseUrl, supabaseAnonKey); - interface Message { id: string; phone_number: string; diff --git a/src/components/panel/MessageComposer.tsx b/src/components/panel/MessageComposer.tsx index 4b8db7c..cb530bf 100644 --- a/src/components/panel/MessageComposer.tsx +++ b/src/components/panel/MessageComposer.tsx @@ -5,17 +5,7 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card } from "@/components/ui/card"; import { toast } from "sonner"; -import { createClient } from "@supabase/supabase-js"; - -// Initialize Supabase client with proper error handling -const supabaseUrl = "https://ikmbnngahzcellthaysf.supabase.co"; -const supabaseAnonKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlrbWJubmdhaHpjZWxsdGhheXNmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDA1ODY5NjUsImV4cCI6MjA1NjE2Mjk2NX0.puDSeLAaTirOPyj6ndF2Mzzu8CKxlwJsoFP6gK8cWuA"; - -if (!supabaseUrl || !supabaseAnonKey) { - throw new Error('Supabase URL and Anon Key are required'); -} - -const supabase = createClient(supabaseUrl, supabaseAnonKey); +import { supabase } from "@/lib/supabase"; export function MessageComposer() { const [message, setMessage] = useState(""); diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts new file mode 100644 index 0000000..cd73c2c --- /dev/null +++ b/src/lib/supabase.ts @@ -0,0 +1,11 @@ + +import { createClient } from "@supabase/supabase-js"; + +const supabaseUrl = "https://ikmbnngahzcellthaysf.supabase.co"; +const supabaseAnonKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlrbWJubmdhaHpjZWxsdGhheXNmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDA1ODY5NjUsImV4cCI6MjA1NjE2Mjk2NX0.puDSeLAaTirOPyj6ndF2Mzzu8CKxlwJsoFP6gK8cWuA"; + +if (!supabaseUrl || !supabaseAnonKey) { + throw new Error('Supabase URL and Anon Key are required'); +} + +export const supabase = createClient(supabaseUrl, supabaseAnonKey);