mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Display plugins from people you follow
This commit is contained in:
8 files changed
+103
-13
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
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 { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
@@ -10,8 +10,10 @@ import { useDiscoverPlugins } from '@/hooks/useDiscoverPlugins';
|
|||||||
import { usePlugins } from '@/hooks/usePlugins';
|
import { usePlugins } from '@/hooks/usePlugins';
|
||||||
import { useAuthor } from '@/hooks/useAuthor';
|
import { useAuthor } from '@/hooks/useAuthor';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
import { genUserName } from '@/lib/genUserName';
|
import { genUserName } from '@/lib/genUserName';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import type { NostrMetadata } from '@nostrify/nostrify';
|
import type { NostrMetadata } from '@nostrify/nostrify';
|
||||||
|
|
||||||
interface DiscoverPluginsDialogProps {
|
interface DiscoverPluginsDialogProps {
|
||||||
@@ -21,6 +23,7 @@ interface DiscoverPluginsDialogProps {
|
|||||||
|
|
||||||
export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDialogProps) {
|
export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDialogProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { user } = useCurrentUser();
|
||||||
const { data: plugins, isLoading } = useDiscoverPlugins();
|
const { data: plugins, isLoading } = useDiscoverPlugins();
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
|
||||||
@@ -61,7 +64,28 @@ export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDia
|
|||||||
|
|
||||||
{/* Plugins List */}
|
{/* Plugins List */}
|
||||||
<div className="flex-1 overflow-y-auto space-y-3 pr-2">
|
<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) => (
|
{[...Array(3)].map((_, i) => (
|
||||||
<Card key={i}>
|
<Card key={i}>
|
||||||
@@ -80,13 +104,28 @@ export function DiscoverPluginsDialog({ open, onOpenChange }: DiscoverPluginsDia
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isLoading && filteredPlugins?.length === 0 && (
|
{user && !isLoading && filteredPlugins?.length === 0 && (
|
||||||
<div className="text-center py-12 text-muted-foreground">
|
<Card className="border-dashed">
|
||||||
{searchQuery ? t('noPluginsFound') : t('noPluginsAvailable')}
|
<CardContent className="py-12 px-8 text-center">
|
||||||
</div>
|
<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} />
|
<PluginCard key={`${plugin.author}-${plugin.id}`} plugin={plugin} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useNostr } from '@nostrify/react';
|
import { useNostr } from '@nostrify/react';
|
||||||
import type { NostrEvent } from '@nostrify/nostrify';
|
import type { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
import { useCurrentUser } from './useCurrentUser';
|
||||||
|
import { useContacts } from './useContacts';
|
||||||
|
|
||||||
export interface DiscoveredPlugin {
|
export interface DiscoveredPlugin {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -15,20 +17,39 @@ export interface DiscoveredPlugin {
|
|||||||
/**
|
/**
|
||||||
* Hook to discover Shakespeare plugins on Nostr
|
* Hook to discover Shakespeare plugins on Nostr
|
||||||
* Queries NIP-34 git repository announcements with t-tag "shakespeare-plugin"
|
* 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() {
|
export function useDiscoverPlugins() {
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
|
const { user } = useCurrentUser();
|
||||||
|
const { data: contacts } = useContacts(user?.pubkey);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['discover-plugins'],
|
queryKey: ['discover-plugins', user?.pubkey, contacts],
|
||||||
queryFn: async (c) => {
|
queryFn: async (c) => {
|
||||||
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]);
|
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
|
// Query NIP-34 repository announcements (kind 30617) with shakespeare-plugin tag
|
||||||
|
// Filter by authors: current user + people they follow
|
||||||
const events = await nostr.query(
|
const events = await nostr.query(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
kinds: [30617],
|
kinds: [30617],
|
||||||
|
authors,
|
||||||
'#t': ['shakespeare-plugin'],
|
'#t': ['shakespeare-plugin'],
|
||||||
limit: 100,
|
limit: 100,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -493,6 +493,11 @@
|
|||||||
"installing": "Installing...",
|
"installing": "Installing...",
|
||||||
"by": "by",
|
"by": "by",
|
||||||
"website": "Website",
|
"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",
|
"mcpServers": "MCP Servers",
|
||||||
"mcpServersDescription": "Connect to Model Context Protocol servers to extend the AI's capabilities with external tools.",
|
"mcpServersDescription": "Connect to Model Context Protocol servers to extend the AI's capabilities with external tools.",
|
||||||
"addMcpServer": "Add MCP Server",
|
"addMcpServer": "Add MCP Server",
|
||||||
|
|||||||
+6
-1
@@ -445,5 +445,10 @@
|
|||||||
"install": "Shigar",
|
"install": "Shigar",
|
||||||
"installing": "Ana Shigarwa...",
|
"installing": "Ana Shigarwa...",
|
||||||
"by": "ta",
|
"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
@@ -442,5 +442,10 @@
|
|||||||
"install": "Wụnye",
|
"install": "Wụnye",
|
||||||
"installing": "Na-ewunye...",
|
"installing": "Na-ewunye...",
|
||||||
"by": "site na",
|
"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
@@ -454,5 +454,10 @@
|
|||||||
"install": "Instalar",
|
"install": "Instalar",
|
||||||
"installing": "Instalando...",
|
"installing": "Instalando...",
|
||||||
"by": "por",
|
"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
@@ -442,5 +442,10 @@
|
|||||||
"install": "Fi Sori Ẹrọ",
|
"install": "Fi Sori Ẹrọ",
|
||||||
"installing": "N Fi Sori Ẹrọ...",
|
"installing": "N Fi Sori Ẹrọ...",
|
||||||
"by": "nipasẹ",
|
"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
@@ -454,5 +454,10 @@
|
|||||||
"install": "安装",
|
"install": "安装",
|
||||||
"installing": "安装中...",
|
"installing": "安装中...",
|
||||||
"by": "作者",
|
"by": "作者",
|
||||||
"website": "网站"
|
"website": "网站",
|
||||||
|
"loginRequired": "需要登录",
|
||||||
|
"loginToDiscoverPlugins": "使用 Nostr 登录以发现您关注的人的插件。",
|
||||||
|
"noPluginsFromNetwork": "未找到插件",
|
||||||
|
"noPluginsFromNetworkDescription": "未找到您关注的人的插件。在 Nostr 上关注插件开发者以在此处查看他们的插件。",
|
||||||
|
"tryDifferentSearch": "尝试不同的搜索词。"
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user