this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fetch existing artist record

Hilke Ros 12f7fdf9 b3c4e14c

+94 -4
+38
app/api/artist/route.ts
··· 4 4 import { getOAuthClient } from "@/lib/auth/client"; 5 5 import * as ch from "@/src/lexicons/ch"; 6 6 7 + export async function GET(request: NextRequest) { 8 + const session = await getSession(); 9 + if (!session) { 10 + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); 11 + } 12 + 13 + try { 14 + const client = await getOAuthClient(); 15 + const oauthSession = await client.restore(session.did); 16 + const lexClient = new Client(oauthSession); 17 + const query = await lexClient.list(ch.indiemusi.alpha.actor.artist, { 18 + limit: 10, 19 + repo: session.did, 20 + }) 21 + 22 + if (query.records.length > 0) { 23 + const record = query.records[0]; 24 + console.log("Fetched artist records:", record.value); 25 + return NextResponse.json({ 26 + success: true, 27 + artist: record.value, 28 + uri: record.uri, 29 + }); 30 + } 31 + 32 + return NextResponse.json({ 33 + success: true, 34 + artist: null, 35 + }); 36 + } catch (error) { 37 + console.error("Failed to fetch artist:", error); 38 + return NextResponse.json( 39 + { error: "Failed to fetch artist" }, 40 + { status: 500 } 41 + ); 42 + } 43 + } 44 + 7 45 export async function POST(request: NextRequest) { 8 46 9 47 const session = await getSession();
+2 -2
app/page.tsx
··· 11 11 <main className="w-full max-w-md mx-auto p-8"> 12 12 <div className="text-center mb-8"> 13 13 <h1 className="text-3xl font-bold text-zinc-900 dark:text-zinc-100 mb-2"> 14 - Statusphere 14 + indiemusi.ch 15 15 </h1> 16 16 <p className="text-zinc-600 dark:text-zinc-400"> 17 - Set your status on the Atmosphere 17 + Manage your music catalogue in the Atmosphere 18 18 </p> 19 19 </div> 20 20
+54 -2
components/ArtistForm.tsx
··· 1 1 "use client"; 2 2 3 - import { useState } from "react"; 3 + import { useState, useEffect } from "react"; 4 4 import { useRouter } from "next/navigation"; 5 5 6 - 6 + interface ArtistProfile { 7 + name: string; 8 + createdAt: string; 9 + } 7 10 8 11 export function ArtistForm() { 9 12 const router = useRouter(); 10 13 const [name, setName] = useState(""); 11 14 const [loading, setLoading] = useState(false); 12 15 const [error, setError] = useState<string | null>(null); 16 + const [existingArtist, setExistingArtist] = useState<ArtistProfile | null>(null); 17 + const [isLoadingArtist, setIsLoadingArtist] = useState(true); 18 + 19 + // Fetch existing artist profile on mount 20 + useEffect(() => { 21 + async function fetchArtist() { 22 + try { 23 + const res = await fetch("/api/artist"); 24 + if (!res.ok) { 25 + throw new Error("Failed to fetch artist"); 26 + } 27 + const data = await res.json(); 28 + if (data.artist) { 29 + setExistingArtist(data.artist); 30 + } 31 + } catch (err) { 32 + console.error("Failed to fetch artist:", err); 33 + } finally { 34 + setIsLoadingArtist(false); 35 + } 36 + } 37 + 38 + fetchArtist(); 39 + }, []); 13 40 14 41 async function handleSubmit(e: React.FormEvent) { 15 42 e.preventDefault(); ··· 36 63 } 37 64 } 38 65 66 + // Show loading state while fetching artist 67 + if (isLoadingArtist) { 68 + return <div className="text-zinc-500">Loading artist profile...</div>; 69 + } 70 + 71 + // Show existing artist profile 72 + if (existingArtist) { 73 + return ( 74 + <div className="space-y-4"> 75 + <div className="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg border border-green-200 dark:border-green-800"> 76 + <h3 className="text-sm font-medium text-green-900 dark:text-green-100 mb-2"> 77 + Artist Profile Found 78 + </h3> 79 + <p className="text-sm text-green-800 dark:text-green-200"> 80 + <strong>Name:</strong> {existingArtist.name} 81 + </p> 82 + <p className="text-xs text-green-700 dark:text-green-300 mt-1"> 83 + Created: {new Date(existingArtist.createdAt).toLocaleDateString()} 84 + </p> 85 + </div> 86 + </div> 87 + ); 88 + } 89 + 90 + // Show form if no existing artist 39 91 return ( 40 92 <form onSubmit={handleSubmit} className="space-y-4"> 41 93 <div>