forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentify-plugin.tsx
More file actions
90 lines (79 loc) · 2.49 KB
/
Copy pathidentify-plugin.tsx
File metadata and controls
90 lines (79 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use client';
import { getCommunityPlugin } from '@/src/actions/plugins/get-community-plugins';
import { CommunityPlugin } from '@/src/types/plugins/plugins.types';
import Image from 'next/image';
import { Fragment, useEffect, useState, memo } from 'react';
import { NavArrowRight } from 'iconoir-react';
import ErrorIdentifyPlugin from './error-identify-plugin';
import IdentifyPluginLoader from './identify-plugin-loader';
import { getPluginFromCache, setPluginInCache, hasPluginInCache } from './plugin-cache';
interface IdentifyPluginProps {
pluginId: string;
}
function IdentifyPlugin({ pluginId }: IdentifyPluginProps) {
const [pluginCommunity, setPluginCommunity] = useState<CommunityPlugin | undefined>(
undefined,
);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Check cache first
if (hasPluginInCache(pluginId)) {
const cachedPlugin = getPluginFromCache(pluginId);
setPluginCommunity(cachedPlugin || undefined);
setLoading(false);
return;
}
// Fetch from API if not in cache
setLoading(true);
getCommunityPlugin(pluginId)
.then((plugin) => {
console.log(plugin);
setPluginCommunity(plugin);
setPluginInCache(pluginId, plugin || null);
})
.finally(() => setLoading(false));
}, [pluginId]);
if (loading) {
return <IdentifyPluginLoader />;
}
if (!pluginCommunity) {
return <ErrorIdentifyPlugin />;
}
const isPublic = !pluginCommunity.private;
const pluginUrl = `https://h.omi.me/apps/${pluginId}`;
const content = (
<>
<Image
className="h-8 w-8 min-w-[32px] rounded-lg object-cover"
src={pluginCommunity?.image}
alt={pluginCommunity?.name}
width={32}
height={32}
/>
<div className="flex-1">
<h3 className="text-base font-semibold text-white">{pluginCommunity?.name}</h3>
<p className="line-clamp-1 text-xs text-zinc-400">
{pluginCommunity.description}
</p>
</div>
{isPublic && <NavArrowRight className="h-4 w-4 text-zinc-500" />}
</>
);
return (
<Fragment>
{isPublic ? (
<a
href={pluginUrl}
target="_blank"
rel="noopener noreferrer"
className="mb-4 flex items-center gap-3 transition-opacity hover:opacity-80"
>
{content}
</a>
) : (
<div className="mb-4 flex items-center gap-3">{content}</div>
)}
</Fragment>
);
}
export default memo(IdentifyPlugin);