Display plugins from people you follow

This commit is contained in:
Alex Gleason committed 2025-12-04 18:06:13 -06:00
1 parent 4c9e688009
commit 9005a2c38e
8 files changed
+103 -13

No files matched your search

+46 -7
View File
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Search, Download, ExternalLink, Loader2, Check, Globe, Package } from 'lucide-react';
import { Search, Download, ExternalLink, Loader2, Check, Globe, Package, LogIn } from 'lucide-react';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -10,8 +10,10 @@ import { useDiscoverPlugins } from '@/hooks/useDiscoverPlugins';
import { usePlugins } from '@/hooks/usePlugins';
import { useAuthor } from '@/hooks/useAuthor';
import { useToast } from '@/hooks/useToast';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { genUserName } from '@/lib/genUserName';
import { Link } from 'react-router-dom';
import type { NostrMetadata } from '@nostrify/nostrify';
interface DiscoverPluginsDialogProps {
@@ -21,6 +23,7 @@ interface DiscoverPluginsDialogProps {
export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDialogProps) {
const { t } = useTranslation();
const { user } = useCurrentUser();
const { data: plugins, isLoading } = useDiscoverPlugins();
const [searchQuery, setSearchQuery] = useState('');
@@ -61,7 +64,28 @@ export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDia
{/* Plugins List */}
<div className="flex-1 overflow-y-auto space-y-3 pr-2">
{isLoading && (
{!user && (
<Card className="border-dashed">
<CardContent className="py-12 px-8 text-center">
<div className="max-w-sm mx-auto space-y-4">
<LogIn className="h-12 w-12 mx-auto text-muted-foreground" />
<div className="space-y-2">
<h3 className="font-semibold">{t('loginRequired')}</h3>
<p className="text-sm text-muted-foreground">
{t('loginToDiscoverPlugins')}
</p>
</div>
<Button asChild className="w-full">
<Link to="/settings/nostr">
{t('goToNostrSettings')}
</Link>
</Button>
</div>
</CardContent>
</Card>
)}
{user && isLoading && (
<>
{[...Array(3)].map((_, i) => (
<Card key={i}>
@@ -80,13 +104,28 @@ export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDia
</>
)}
{!isLoading && filteredPlugins?.length === 0 && (
<div className="text-center py-12 text-muted-foreground">
{searchQuery ? t('noPluginsFound') : t('noPluginsAvailable')}
</div>
{user && !isLoading && filteredPlugins?.length === 0 && (
<Card className="border-dashed">
<CardContent className="py-12 px-8 text-center">
<div className="max-w-sm mx-auto space-y-4">
<Package className="h-12 w-12 mx-auto text-muted-foreground" />
<div className="space-y-2">
<h3 className="font-semibold">
{searchQuery ? t('noPluginsFound') : t('noPluginsFromNetwork')}
</h3>
<p className="text-sm text-muted-foreground">
{searchQuery
? t('tryDifferentSearch')
: t('noPluginsFromNetworkDescription')
}
</p>
</div>
</div>
</CardContent>
</Card>
)}
{!isLoading && filteredPlugins?.map((plugin) => (
{user && !isLoading && filteredPlugins?.map((plugin) => (
<PluginCard key={`${plugin.author}-${plugin.id}`} plugin={plugin} />
))}
</div>
+22 -1
View File
@@ -1,6 +1,8 @@
import { useQuery } from '@tanstack/react-query';
import { useNostr } from '@nostrify/react';
import type { NostrEvent } from '@nostrify/nostrify';
import { useCurrentUser } from './useCurrentUser';
import { useContacts } from './useContacts';
export interface DiscoveredPlugin {
id: string;
@@ -15,20 +17,39 @@ export interface DiscoveredPlugin {
/**
* Hook to discover Shakespeare plugins on Nostr
* Queries NIP-34 git repository announcements with t-tag "shakespeare-plugin"
* Filters to only show plugins by the current user and people they follow
*/
export function useDiscoverPlugins() {
const { nostr } = useNostr();
const { user } = useCurrentUser();
const { data: contacts } = useContacts(user?.pubkey);
return useQuery({
queryKey: ['discover-plugins'],
queryKey: ['discover-plugins', user?.pubkey, contacts],
queryFn: async (c) => {
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]);
// Build authors list: current user + people they follow
const authors: string[] = [];
if (user?.pubkey) {
authors.push(user.pubkey);
}
if (contacts && contacts.length > 0) {
authors.push(...contacts);
}
// If no authors (user not logged in or no follows), return empty array
if (authors.length === 0) {
return [];
}
// Query NIP-34 repository announcements (kind 30617) with shakespeare-plugin tag
// Filter by authors: current user + people they follow
const events = await nostr.query(
[
{
kinds: [30617],
authors,
'#t': ['shakespeare-plugin'],
limit: 100,
},
+5
View File
@@ -493,6 +493,11 @@
"installing": "Installing...",
"by": "by",
"website": "Website",
"loginRequired": "Login Required",
"loginToDiscoverPlugins": "Log in with Nostr to discover plugins from people you follow.",
"noPluginsFromNetwork": "No Plugins Found",
"noPluginsFromNetworkDescription": "No plugins found from people you follow. Follow plugin developers on Nostr to see their plugins here.",
"tryDifferentSearch": "Try a different search term.",
"mcpServers": "MCP Servers",
"mcpServersDescription": "Connect to Model Context Protocol servers to extend the AI's capabilities with external tools.",
"addMcpServer": "Add MCP Server",
+6 -1
View File
@@ -445,5 +445,10 @@
"install": "Shigar",
"installing": "Ana Shigarwa...",
"by": "ta",
"website": "Gidan Yanar Gizo"
"website": "Gidan Yanar Gizo",
"loginRequired": "Ana Buƙatar Shiga",
"loginToDiscoverPlugins": "Shiga tare da Nostr don gano plugins daga mutanen da kuke bi.",
"noPluginsFromNetwork": "Ba a Sami Plugin ba",
"noPluginsFromNetworkDescription": "Ba a sami plugins daga mutanen da kuke bi ba. Bi masu haɓaka plugins akan Nostr don ganin plugins nasu a nan.",
"tryDifferentSearch": "Gwada kalmar bincike daban."
}
+6 -1
View File
@@ -442,5 +442,10 @@
"install": "Wụnye",
"installing": "Na-ewunye...",
"by": "site na",
"website": "Webụsaịtị"
"website": "Webụsaịtị",
"loginRequired": "Achọrọ Nbanye",
"loginToDiscoverPlugins": "Banye na Nostr iji chọpụta plugins sitere na ndị ị na-eso.",
"noPluginsFromNetwork": "Achọtaghị Plugins",
"noPluginsFromNetworkDescription": "Achọtaghị plugins sitere na ndị ị na-eso. Soro ndị mmepe plugin na Nostr iji hụ plugins ha ebe a.",
"tryDifferentSearch": "Gbalịa okwu nchọgharị dị iche."
}
+6 -1
View File
@@ -454,5 +454,10 @@
"install": "Instalar",
"installing": "Instalando...",
"by": "por",
"website": "Site"
"website": "Site",
"loginRequired": "Login Necessário",
"loginToDiscoverPlugins": "Faça login com Nostr para descobrir plugins de pessoas que você segue.",
"noPluginsFromNetwork": "Nenhum Plugin Encontrado",
"noPluginsFromNetworkDescription": "Nenhum plugin encontrado de pessoas que você segue. Siga desenvolvedores de plugins no Nostr para ver seus plugins aqui.",
"tryDifferentSearch": "Tente um termo de busca diferente."
}
+6 -1
View File
@@ -442,5 +442,10 @@
"install": "Fi Sori Ẹrọ",
"installing": "N Fi Sori Ẹrọ...",
"by": "nipasẹ",
"website": "Oju opo wẹẹbu"
"website": "Oju opo wẹẹbu",
"loginRequired": "Wiwọle Nilo",
"loginToDiscoverPlugins": "Wọle pẹlu Nostr lati ṣawari awọn plugins lati ọdọ awọn eniyan ti o ntẹle.",
"noPluginsFromNetwork": "Ko Ri Plugins",
"noPluginsFromNetworkDescription": "Ko ri awọn plugins lati ọdọ awọn eniyan ti o ntẹle. Tẹle awọn olupilẹṣẹ plugin lori Nostr lati rii awọn plugins wọn nibi.",
"tryDifferentSearch": "Gbiyanju ọrọ wiwa miiran."
}
+6 -1
View File
@@ -454,5 +454,10 @@
"install": "安装",
"installing": "安装中...",
"by": "作者",
"website": "网站"
"website": "网站",
"loginRequired": "需要登录",
"loginToDiscoverPlugins": "使用 Nostr 登录以发现您关注的人的插件。",
"noPluginsFromNetwork": "未找到插件",
"noPluginsFromNetworkDescription": "未找到您关注的人的插件。在 Nostr 上关注插件开发者以在此处查看他们的插件。",
"tryDifferentSearch": "尝试不同的搜索词。"
}