mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 08:47:23 +00:00
change var names, remove unused, change component to pure style
This commit is contained in:
1 parent
b132e4847d
commit
51be437219
4 files changed
+32
-61
No files matched your search
@@ -9,7 +9,6 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { Card } from '@/components/ui/card';
|
import { Card } from '@/components/ui/card';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { ArrowLeft, Send, Loader2 } from 'lucide-react';
|
import { ArrowLeft, Send, Loader2 } from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@@ -20,7 +19,7 @@ interface ChatAreaProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function MessageBubble({
|
const MessageBubble = ({
|
||||||
message,
|
message,
|
||||||
isFromCurrentUser
|
isFromCurrentUser
|
||||||
}: {
|
}: {
|
||||||
@@ -32,7 +31,7 @@ function MessageBubble({
|
|||||||
isSending?: boolean;
|
isSending?: boolean;
|
||||||
};
|
};
|
||||||
isFromCurrentUser: boolean;
|
isFromCurrentUser: boolean;
|
||||||
}) {
|
}) => {
|
||||||
const formatTime = (timestamp: number) => {
|
const formatTime = (timestamp: number) => {
|
||||||
const date = new Date(timestamp * 1000);
|
const date = new Date(timestamp * 1000);
|
||||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
@@ -67,9 +66,9 @@ function MessageBubble({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function ChatHeader({ pubkey, onBack }: { pubkey: string; onBack?: () => void }) {
|
const ChatHeader = ({ pubkey, onBack }: { pubkey: string; onBack?: () => void }) => {
|
||||||
const author = useAuthor(pubkey);
|
const author = useAuthor(pubkey);
|
||||||
const metadata = author.data?.metadata;
|
const metadata = author.data?.metadata;
|
||||||
|
|
||||||
@@ -103,9 +102,9 @@ function ChatHeader({ pubkey, onBack }: { pubkey: string; onBack?: () => void })
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function EmptyState() {
|
const EmptyState = () => {
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex items-center justify-center p-8">
|
<div className="h-full flex items-center justify-center p-8">
|
||||||
<div className="text-center text-muted-foreground max-w-sm">
|
<div className="text-center text-muted-foreground max-w-sm">
|
||||||
@@ -116,35 +115,9 @@ function EmptyState() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function ChatAreaSkeleton() {
|
export const ChatArea = ({ pubkey, onBack, className }: ChatAreaProps) => {
|
||||||
return (
|
|
||||||
<div className="h-full flex flex-col">
|
|
||||||
<div className="p-4 border-b flex items-center gap-3">
|
|
||||||
<Skeleton className="h-10 w-10 rounded-full" />
|
|
||||||
<div className="flex-1 space-y-2">
|
|
||||||
<Skeleton className="h-4 w-32" />
|
|
||||||
<Skeleton className="h-3 w-24" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex-1 p-4 space-y-4">
|
|
||||||
{[1, 2, 3].map((i) => (
|
|
||||||
<div key={i} className={cn("flex", i % 2 === 0 ? "justify-end" : "justify-start")}>
|
|
||||||
<Skeleton className="h-16 w-64 rounded-lg" />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4 border-t">
|
|
||||||
<Skeleton className="h-20 w-full" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ChatArea({ pubkey, onBack, className }: ChatAreaProps) {
|
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { sendMessage, isNIP17Enabled } = useDMContext();
|
const { sendMessage, isNIP17Enabled } = useDMContext();
|
||||||
const { messages, totalCount } = useConversationMessages(pubkey || '');
|
const { messages, totalCount } = useConversationMessages(pubkey || '');
|
||||||
@@ -268,5 +241,4 @@ export function ChatArea({ pubkey, onBack, className }: ChatAreaProps) {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ interface ConversationListProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConversationItem({
|
const ConversationItem = ({
|
||||||
pubkey,
|
pubkey,
|
||||||
isSelected,
|
isSelected,
|
||||||
onClick,
|
onClick,
|
||||||
@@ -28,7 +28,7 @@ function ConversationItem({
|
|||||||
lastMessage: { decryptedContent?: string; error?: string } | null;
|
lastMessage: { decryptedContent?: string; error?: string } | null;
|
||||||
lastActivity: number;
|
lastActivity: number;
|
||||||
hasNIP17Messages: boolean;
|
hasNIP17Messages: boolean;
|
||||||
}) {
|
}) => {
|
||||||
const author = useAuthor(pubkey);
|
const author = useAuthor(pubkey);
|
||||||
const metadata = author.data?.metadata;
|
const metadata = author.data?.metadata;
|
||||||
|
|
||||||
@@ -88,9 +88,9 @@ function ConversationItem({
|
|||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function ConversationListSkeleton() {
|
const ConversationListSkeleton = () => {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2 p-4">
|
<div className="space-y-2 p-4">
|
||||||
{[1, 2, 3, 4, 5].map((i) => (
|
{[1, 2, 3, 4, 5].map((i) => (
|
||||||
@@ -107,9 +107,9 @@ function ConversationListSkeleton() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export function ConversationList({
|
export const ConversationList = ({
|
||||||
selectedPubkey,
|
selectedPubkey,
|
||||||
onSelectConversation,
|
onSelectConversation,
|
||||||
className
|
className
|
||||||
@@ -161,5 +161,4 @@ export function ConversationList({
|
|||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
@@ -105,12 +105,12 @@ export const DMStatusInfo = ({ clearCache }: DMStatusInfoProps) => {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Scan Progress */}
|
{/* Scan Progress */}
|
||||||
{(scanProgress.nip4 || scanProgress.nip17) && (
|
{(scanProgress.nip4 !== null || scanProgress.nip17 !== null) && (
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent className="pt-6">
|
<CardContent className="pt-6">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<p className="text-sm font-medium">Scanning Messages</p>
|
<p className="text-sm font-medium">Scanning Messages</p>
|
||||||
{scanProgress.nip4 && (
|
{scanProgress.nip4 !== null && (
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<div className="flex items-center justify-between text-xs">
|
<div className="flex items-center justify-between text-xs">
|
||||||
<span className="text-muted-foreground">NIP-4 (Legacy)</span>
|
<span className="text-muted-foreground">NIP-4 (Legacy)</span>
|
||||||
@@ -119,7 +119,7 @@ export const DMStatusInfo = ({ clearCache }: DMStatusInfoProps) => {
|
|||||||
<p className="text-xs text-muted-foreground">{scanProgress.nip4.status}</p>
|
<p className="text-xs text-muted-foreground">{scanProgress.nip4.status}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{scanProgress.nip17 && (
|
{scanProgress.nip17 !== null && (
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<div className="flex items-center justify-between text-xs">
|
<div className="flex items-center justify-between text-xs">
|
||||||
<span className="text-muted-foreground">NIP-17 (Private)</span>
|
<span className="text-muted-foreground">NIP-17 (Private)</span>
|
||||||
@@ -141,14 +141,14 @@ export const DMStatusInfo = ({ clearCache }: DMStatusInfoProps) => {
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-sm text-muted-foreground">NIP-4 (Legacy DMs)</span>
|
<span className="text-sm text-muted-foreground">NIP-4 (Legacy DMs)</span>
|
||||||
<Badge variant={subscriptions.nip4 ? 'default' : 'secondary'}>
|
<Badge variant={subscriptions.isNIP4Connected ? 'default' : 'secondary'}>
|
||||||
{subscriptions.nip4 ? 'Connected' : 'Disconnected'}
|
{subscriptions.isNIP4Connected ? 'Connected' : 'Disconnected'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-sm text-muted-foreground">NIP-17 (Private DMs)</span>
|
<span className="text-sm text-muted-foreground">NIP-17 (Private DMs)</span>
|
||||||
<Badge variant={subscriptions.nip17 ? 'default' : 'secondary'}>
|
<Badge variant={subscriptions.isNIP17Connected ? 'default' : 'secondary'}>
|
||||||
{subscriptions.nip17 ? 'Connected' : 'Disconnected'}
|
{subscriptions.isNIP17Connected ? 'Connected' : 'Disconnected'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ interface LastSyncData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface SubscriptionStatus {
|
interface SubscriptionStatus {
|
||||||
nip4: boolean;
|
isNIP4Connected: boolean;
|
||||||
nip17: boolean;
|
isNIP17Connected: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ScanProgress {
|
interface ScanProgress {
|
||||||
@@ -181,8 +181,8 @@ export function DMProvider({ children, enableNIP17 = true }: DMProviderProps) {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [loadingPhase, setLoadingPhase] = useState<LoadingPhase>(LOADING_PHASES.IDLE);
|
const [loadingPhase, setLoadingPhase] = useState<LoadingPhase>(LOADING_PHASES.IDLE);
|
||||||
const [subscriptions, setSubscriptions] = useState<SubscriptionStatus>({
|
const [subscriptions, setSubscriptions] = useState<SubscriptionStatus>({
|
||||||
nip4: false,
|
isNIP4Connected: false,
|
||||||
nip17: false
|
isNIP17Connected: false
|
||||||
});
|
});
|
||||||
const [hasInitialLoadCompleted, setHasInitialLoadCompleted] = useState(false);
|
const [hasInitialLoadCompleted, setHasInitialLoadCompleted] = useState(false);
|
||||||
const [shouldSaveImmediately, setShouldSaveImmediately] = useState(false);
|
const [shouldSaveImmediately, setShouldSaveImmediately] = useState(false);
|
||||||
@@ -797,10 +797,10 @@ export function DMProvider({ children, enableNIP17 = true }: DMProviderProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setSubscriptions(prev => ({ ...prev, nip4: true }));
|
setSubscriptions(prev => ({ ...prev, isNIP4Connected: true }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[DM] Failed to start NIP-4 subscription:', error);
|
console.error('[DM] Failed to start NIP-4 subscription:', error);
|
||||||
setSubscriptions(prev => ({ ...prev, nip4: false }));
|
setSubscriptions(prev => ({ ...prev, isNIP4Connected: false }));
|
||||||
}
|
}
|
||||||
}, [user, nostr, lastSync.nip4, processIncomingNIP4Message]);
|
}, [user, nostr, lastSync.nip4, processIncomingNIP4Message]);
|
||||||
|
|
||||||
@@ -848,10 +848,10 @@ export function DMProvider({ children, enableNIP17 = true }: DMProviderProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setSubscriptions(prev => ({ ...prev, nip17: true }));
|
setSubscriptions(prev => ({ ...prev, isNIP17Connected: true }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[DM] Failed to start NIP-17 subscription:', error);
|
console.error('[DM] Failed to start NIP-17 subscription:', error);
|
||||||
setSubscriptions(prev => ({ ...prev, nip17: false }));
|
setSubscriptions(prev => ({ ...prev, isNIP17Connected: false }));
|
||||||
}
|
}
|
||||||
}, [user, nostr, lastSync.nip17, enableNIP17, processIncomingNIP17Message]);
|
}, [user, nostr, lastSync.nip17, enableNIP17, processIncomingNIP17Message]);
|
||||||
|
|
||||||
@@ -929,7 +929,7 @@ export function DMProvider({ children, enableNIP17 = true }: DMProviderProps) {
|
|||||||
if (debouncedWriteRef.current) {
|
if (debouncedWriteRef.current) {
|
||||||
clearTimeout(debouncedWriteRef.current);
|
clearTimeout(debouncedWriteRef.current);
|
||||||
}
|
}
|
||||||
setSubscriptions({ nip4: false, nip17: false });
|
setSubscriptions({ isNIP4Connected: false, isNIP17Connected: false });
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user