Back up recovered AnchorHost frontend
This commit is contained in:
commit
4ce031f667
72 files changed
+37643
No files matched your search
@@ -0,0 +1,516 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { ArrowLeft, Download, Star, Calendar, Package, ExternalLink, Tag, Server, ChevronDown } from 'lucide-react';
|
||||
import { colors } from '../../theme/colors';
|
||||
|
||||
import { API_BASE_URL, WS_BASE_URL as WS_URL } from '../../config/api';
|
||||
|
||||
function PluginDetails() {
|
||||
const { pluginId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [plugin, setPlugin] = useState(null);
|
||||
const [versions, setVersions] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [selectedVersion, setSelectedVersion] = useState(null);
|
||||
const [servers, setServers] = useState([]);
|
||||
const [selectedServer, setSelectedServer] = useState(null);
|
||||
const [showServerDropdown, setShowServerDropdown] = useState(false);
|
||||
const [downloadingToServer, setDownloadingToServer] = useState(false);
|
||||
const [downloadStatus, setDownloadStatus] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPluginDetails = async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
// Fetch project details
|
||||
const projectResponse = await fetch(
|
||||
`${API_BASE_URL}/api/modrinth/project/${pluginId}`,
|
||||
{
|
||||
headers: {
|
||||
'User-Agent': 'AnchorHost/1.0'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!projectResponse.ok) {
|
||||
throw new Error('Failed to fetch plugin details');
|
||||
}
|
||||
|
||||
const projectData = await projectResponse.json();
|
||||
setPlugin(projectData);
|
||||
|
||||
// Fetch versions
|
||||
const versionsResponse = await fetch(
|
||||
`${API_BASE_URL}/api/modrinth/project/${pluginId}/versions`
|
||||
);
|
||||
|
||||
if (versionsResponse.ok) {
|
||||
const versionsData = await versionsResponse.json();
|
||||
setVersions(versionsData);
|
||||
if (versionsData.length > 0) {
|
||||
setSelectedVersion(versionsData[0]);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
console.error('Error fetching plugin details:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchServers = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('anchorhost_token');
|
||||
if (!token) return;
|
||||
|
||||
const ws = new WebSocket(`${WS_URL}?token=${token}`);
|
||||
|
||||
ws.onopen = () => {
|
||||
ws.send(JSON.stringify({ type: 'get_servers' }));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'servers_list') {
|
||||
// Filter only Minecraft servers
|
||||
const minecraftServers = (data.servers || []).filter(
|
||||
server => server.image === 'minecraft' && server.type === 'game'
|
||||
);
|
||||
setServers(minecraftServers);
|
||||
ws.close();
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('WebSocket error:', error);
|
||||
ws.close();
|
||||
};
|
||||
} catch (err) {
|
||||
console.error('Error fetching servers:', err);
|
||||
}
|
||||
};
|
||||
|
||||
if (pluginId) {
|
||||
fetchPluginDetails();
|
||||
fetchServers();
|
||||
}
|
||||
}, [pluginId]);
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
if (!dateString) return 'Unknown';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
|
||||
};
|
||||
|
||||
const handleDownload = () => {
|
||||
if (selectedVersion && selectedVersion.files && selectedVersion.files.length > 0) {
|
||||
const primaryFile = selectedVersion.files.find(f => f.primary) || selectedVersion.files[0];
|
||||
window.open(primaryFile.url, '_blank');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadToServer = async () => {
|
||||
if (!selectedServer || !selectedVersion) {
|
||||
setError('Please select a server first');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedVersion.files || selectedVersion.files.length === 0) {
|
||||
setError('No file available for this version');
|
||||
return;
|
||||
}
|
||||
|
||||
const primaryFile = selectedVersion.files.find(f => f.primary) || selectedVersion.files[0];
|
||||
setDownloadingToServer(true);
|
||||
setDownloadStatus('Downloading plugin...');
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem('anchorhost_token');
|
||||
if (!token) {
|
||||
throw new Error('Not authenticated');
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/plugins/download-to-server`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
server_id: selectedServer.id,
|
||||
plugin_url: primaryFile.url,
|
||||
plugin_name: plugin.title || pluginId,
|
||||
file_name: primaryFile.filename || `${pluginId}.jar`
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || 'Failed to download plugin to server');
|
||||
}
|
||||
|
||||
setDownloadStatus('Plugin downloaded successfully!');
|
||||
setTimeout(() => {
|
||||
setDownloadStatus('');
|
||||
setDownloadingToServer(false);
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
setDownloadingToServer(false);
|
||||
setDownloadStatus('');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-app flex items-center justify-center" style={{ backgroundColor: colors.background }}>
|
||||
<div className="w-8 h-8 border-4 border-current border-t-transparent rounded-full animate-spin" style={{ color: colors.blue }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error || !plugin) {
|
||||
return (
|
||||
<div className="min-h-app flex items-center justify-center" style={{ backgroundColor: colors.background }}>
|
||||
<div className="text-center">
|
||||
<p className="text-lg mb-4" style={{ color: colors.brightRed }}>{error || 'Plugin not found'}</p>
|
||||
<button
|
||||
onClick={() => navigate('/plugins')}
|
||||
className="px-6 py-3 rounded-xl border transition-all"
|
||||
style={{
|
||||
backgroundColor: colors.blue,
|
||||
borderColor: colors.blue,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
Back to Store
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-app" style={{ backgroundColor: colors.background }}>
|
||||
<div className="max-w-5xl mx-auto px-4 py-8">
|
||||
{/* Back Button */}
|
||||
<button
|
||||
onClick={() => navigate('/plugins')}
|
||||
className="mb-6 flex items-center gap-2 px-4 py-2 rounded-xl border transition-all hover:scale-105"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
borderColor: colors.brightBlack,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4" />
|
||||
Back to Store
|
||||
</button>
|
||||
|
||||
{/* Plugin Header */}
|
||||
<div className="rounded-xl border p-6 mb-6" style={{ backgroundColor: colors.backgroundSecondary, borderColor: colors.brightBlack }}>
|
||||
<div className="flex items-start gap-6">
|
||||
{plugin.icon_url ? (
|
||||
<img
|
||||
src={plugin.icon_url}
|
||||
alt={plugin.title}
|
||||
className="w-24 h-24 rounded-xl object-cover flex-shrink-0"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className="w-24 h-24 rounded-xl flex items-center justify-center flex-shrink-0"
|
||||
style={{ backgroundColor: colors.brightBlack }}
|
||||
>
|
||||
<Package className="w-12 h-12" style={{ color: colors.foreground }} />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1">
|
||||
<h1 className="text-3xl font-bold mb-2" style={{ color: colors.brightWhite }}>
|
||||
{plugin.title}
|
||||
</h1>
|
||||
<p className="text-lg mb-4" style={{ color: colors.foreground }}>
|
||||
by {plugin.team || (plugin.team_data && plugin.team_data.name) || 'Unknown'}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-4 text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Download className="w-4 h-4" style={{ color: colors.blue }} />
|
||||
<span style={{ color: colors.foreground }}>{plugin.downloads?.toLocaleString() || 0} downloads</span>
|
||||
</div>
|
||||
{plugin.followers !== undefined && (
|
||||
<div className="flex items-center gap-2">
|
||||
<Star className="w-4 h-4" style={{ color: colors.yellow }} />
|
||||
<span style={{ color: colors.foreground }}>{plugin.followers?.toLocaleString() || 0} followers</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<Calendar className="w-4 h-4" style={{ color: colors.foreground }} />
|
||||
<span style={{ color: colors.foreground }}>Updated {formatDate(plugin.updated)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
href={`https://modrinth.com/project/${plugin.slug || pluginId}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="px-4 py-2 rounded-xl border transition-all hover:scale-105 flex items-center gap-2"
|
||||
style={{
|
||||
backgroundColor: colors.blue,
|
||||
borderColor: colors.blue,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
View on Modrinth
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
{plugin.description && (
|
||||
<div className="rounded-xl border p-6 mb-6" style={{ backgroundColor: colors.backgroundSecondary, borderColor: colors.brightBlack }}>
|
||||
<h2 className="text-xl font-semibold mb-4" style={{ color: colors.brightWhite }}>Description</h2>
|
||||
<div
|
||||
className="prose prose-invert max-w-none"
|
||||
style={{ color: colors.foreground }}
|
||||
dangerouslySetInnerHTML={{ __html: plugin.description }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Categories/Tags */}
|
||||
{plugin.categories && plugin.categories.length > 0 && (
|
||||
<div className="rounded-xl border p-6 mb-6" style={{ backgroundColor: colors.backgroundSecondary, borderColor: colors.brightBlack }}>
|
||||
<h2 className="text-xl font-semibold mb-4 flex items-center gap-2" style={{ color: colors.brightWhite }}>
|
||||
<Tag className="w-5 h-5" />
|
||||
Categories
|
||||
</h2>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{plugin.categories.map((category) => (
|
||||
<span
|
||||
key={category}
|
||||
className="px-3 py-1 rounded-lg text-sm"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{category}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Loaders and Versions */}
|
||||
{(plugin.loaders || plugin.game_versions) && (
|
||||
<div className="rounded-xl border p-6 mb-6" style={{ backgroundColor: colors.backgroundSecondary, borderColor: colors.brightBlack }}>
|
||||
<h2 className="text-xl font-semibold mb-4" style={{ color: colors.brightWhite }}>Compatibility</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{plugin.loaders && plugin.loaders.length > 0 && (
|
||||
<div>
|
||||
<h3 className="text-sm font-medium mb-2" style={{ color: colors.foreground }}>Supported Loaders</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{plugin.loaders.map((loader) => (
|
||||
<span
|
||||
key={loader}
|
||||
className="px-3 py-1 rounded-lg text-sm"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{loader}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{plugin.game_versions && plugin.game_versions.length > 0 && (
|
||||
<div>
|
||||
<h3 className="text-sm font-medium mb-2" style={{ color: colors.foreground }}>Supported Versions</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{plugin.game_versions.slice(0, 10).map((version) => (
|
||||
<span
|
||||
key={version}
|
||||
className="px-3 py-1 rounded-lg text-sm"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{version}
|
||||
</span>
|
||||
))}
|
||||
{plugin.game_versions.length > 10 && (
|
||||
<span className="px-3 py-1 rounded-lg text-sm" style={{ color: colors.foreground }}>
|
||||
+{plugin.game_versions.length - 10} more
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Versions */}
|
||||
{versions.length > 0 && (
|
||||
<div className="rounded-xl border p-6 mb-6" style={{ backgroundColor: colors.backgroundSecondary, borderColor: colors.brightBlack }}>
|
||||
<h2 className="text-xl font-semibold mb-4" style={{ color: colors.brightWhite }}>Versions</h2>
|
||||
<div className="space-y-3">
|
||||
{versions.slice(0, 10).map((version) => (
|
||||
<div
|
||||
key={version.id}
|
||||
className={`p-4 rounded-lg border cursor-pointer transition-all ${
|
||||
selectedVersion?.id === version.id ? 'ring-2' : ''
|
||||
}`}
|
||||
style={{
|
||||
backgroundColor: selectedVersion?.id === version.id ? colors.brightBlack : colors.black,
|
||||
borderColor: selectedVersion?.id === version.id ? colors.blue : colors.brightBlack
|
||||
}}
|
||||
onClick={() => setSelectedVersion(version)}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="font-semibold mb-1" style={{ color: colors.brightWhite }}>
|
||||
{version.name}
|
||||
</h3>
|
||||
<div className="flex flex-wrap gap-2 text-sm">
|
||||
{version.game_versions && version.game_versions.map((v) => (
|
||||
<span
|
||||
key={v}
|
||||
className="px-2 py-1 rounded text-xs"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{v}
|
||||
</span>
|
||||
))}
|
||||
{version.loaders && version.loaders.map((l) => (
|
||||
<span
|
||||
key={l}
|
||||
className="px-2 py-1 rounded text-xs"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{l}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-sm" style={{ color: colors.foreground }}>
|
||||
{formatDate(version.date_published)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Download Buttons */}
|
||||
{selectedVersion && selectedVersion.files && selectedVersion.files.length > 0 && (
|
||||
<div className="sticky bottom-4 space-y-3">
|
||||
{/* Server Selection Dropdown */}
|
||||
{servers.length > 0 && (
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setShowServerDropdown(!showServerDropdown)}
|
||||
className="w-full py-3 rounded-xl border font-medium transition-all hover:scale-105 flex items-center justify-between px-4"
|
||||
style={{
|
||||
backgroundColor: colors.backgroundSecondary,
|
||||
borderColor: colors.brightBlack,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<Server className="w-4 h-4" />
|
||||
<span>{selectedServer ? selectedServer.name : 'Select a server to download to'}</span>
|
||||
</div>
|
||||
<ChevronDown className={`w-4 h-4 transition-transform ${showServerDropdown ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
|
||||
{showServerDropdown && (
|
||||
<div
|
||||
className="absolute bottom-full mb-2 w-full rounded-xl border overflow-hidden z-10 max-h-60 overflow-y-auto"
|
||||
style={{
|
||||
backgroundColor: colors.backgroundSecondary,
|
||||
borderColor: colors.brightBlack
|
||||
}}
|
||||
>
|
||||
{servers.map((server) => (
|
||||
<button
|
||||
key={server.id}
|
||||
onClick={() => {
|
||||
setSelectedServer(server);
|
||||
setShowServerDropdown(false);
|
||||
}}
|
||||
className="w-full px-4 py-3 text-left hover:bg-opacity-50 transition-all"
|
||||
style={{
|
||||
backgroundColor: selectedServer?.id === server.id ? colors.blue : 'transparent',
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<div className="font-medium">{server.name}</div>
|
||||
<div className="text-xs opacity-75">{server.version || 'Unknown version'}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Download to Server Button */}
|
||||
{selectedServer && (
|
||||
<button
|
||||
onClick={handleDownloadToServer}
|
||||
disabled={downloadingToServer}
|
||||
className="w-full py-4 rounded-xl border font-semibold text-lg transition-all hover:scale-105 flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
style={{
|
||||
backgroundColor: colors.green,
|
||||
borderColor: colors.green,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
{downloadingToServer ? (
|
||||
<>
|
||||
<div className="w-5 h-5 border-2 border-current border-t-transparent rounded-full animate-spin" />
|
||||
{downloadStatus || 'Downloading...'}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="w-5 h-5" />
|
||||
Download to {selectedServer.name}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Regular Download Button */}
|
||||
<button
|
||||
onClick={handleDownload}
|
||||
className="w-full py-4 rounded-xl border font-semibold text-lg transition-all hover:scale-105 flex items-center justify-center gap-2"
|
||||
style={{
|
||||
backgroundColor: colors.blue,
|
||||
borderColor: colors.blue,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<Download className="w-5 h-5" />
|
||||
Download {selectedVersion.name} to Computer
|
||||
</button>
|
||||
|
||||
{/* Download Status */}
|
||||
{downloadStatus && (
|
||||
<div
|
||||
className="px-4 py-3 rounded-xl text-sm"
|
||||
style={{
|
||||
backgroundColor: downloadStatus.includes('success') ? colors.green : colors.blue,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
{downloadStatus}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PluginDetails;
|
||||
@@ -0,0 +1,360 @@
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import {
|
||||
Search,
|
||||
Filter,
|
||||
Download,
|
||||
ChevronDown,
|
||||
Check,
|
||||
Package,
|
||||
Calendar
|
||||
} from "lucide-react";
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { colors } from '../../theme/colors';
|
||||
|
||||
import { API_BASE_URL } from '../../config/api';
|
||||
|
||||
const PluginStore = () => {
|
||||
const [plugins, setPlugins] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedGameVersion, setSelectedGameVersion] = useState('');
|
||||
const [currentPage, setCurrentPage] = useState(0);
|
||||
const [totalResults, setTotalResults] = useState(0);
|
||||
const [error, setError] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
// ... (colors object)
|
||||
|
||||
const gameVersions = [
|
||||
// ...
|
||||
];
|
||||
|
||||
const searchPlugins = useCallback(async (query = '', page = 0) => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
query: query || '',
|
||||
limit: '20',
|
||||
offset: (page * 20).toString(),
|
||||
project_type: 'plugin'
|
||||
});
|
||||
|
||||
if (selectedGameVersion) {
|
||||
params.append('game_versions', selectedGameVersion);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/modrinth/search?${params.toString()}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to search plugins');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setPlugins(data.hits || []);
|
||||
setTotalResults(data.total_hits || 0);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
console.error('Error searching plugins:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [selectedGameVersion]);
|
||||
|
||||
useEffect(() => {
|
||||
searchPlugins(searchQuery, currentPage);
|
||||
}, [searchPlugins, searchQuery, currentPage]);
|
||||
|
||||
const handleSearch = (e) => {
|
||||
e.preventDefault();
|
||||
setCurrentPage(0);
|
||||
searchPlugins(searchQuery, 0);
|
||||
};
|
||||
|
||||
const handlePluginClick = (pluginId) => {
|
||||
navigate(`/plugins/${pluginId}`);
|
||||
};
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
if (!dateString) return 'Unknown';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
};
|
||||
|
||||
const truncateDescription = (text, maxLength = 150) => {
|
||||
if (!text) return 'No description available';
|
||||
if (text.length <= maxLength) return text;
|
||||
return text.substring(0, maxLength) + '...';
|
||||
};
|
||||
|
||||
// Custom Dropdown Component (same style as ticket management)
|
||||
const Dropdown = ({ value, options, onChange, placeholder, icon: Icon }) => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const ref = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClick = (e) => {
|
||||
if (ref.current && !ref.current.contains(e.target)) setIsOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', handleClick);
|
||||
return () => document.removeEventListener('mousedown', handleClick);
|
||||
}, []);
|
||||
|
||||
const selected = options.find(o => o.value === value);
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
className="w-full rounded-xl px-4 py-3 flex items-center justify-between transition-all duration-200 border-2"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
borderColor: isOpen ? colors.blue : 'transparent',
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
{Icon && <Icon className="w-4 h-4" style={{ color: colors.foreground }} />}
|
||||
<span className="text-sm">{selected?.label || placeholder}</span>
|
||||
</div>
|
||||
<ChevronDown className={`w-4 h-4 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
|
||||
{isOpen && (
|
||||
<div className="absolute z-20 w-full mt-2 rounded-xl shadow-xl border overflow-hidden"
|
||||
style={{
|
||||
backgroundColor: colors.black,
|
||||
borderColor: colors.blue
|
||||
}}>
|
||||
<div className="max-h-48 overflow-auto">
|
||||
{options.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onChange(option.value);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className="w-full text-left px-4 py-3 flex items-center justify-between transition-all duration-150 text-sm hover:opacity-80"
|
||||
style={{
|
||||
color: colors.brightWhite,
|
||||
backgroundColor: value === option.value ? `${colors.blue}20` : 'transparent'
|
||||
}}
|
||||
>
|
||||
<span>{option.label}</span>
|
||||
{value === option.value && (
|
||||
<Check className="w-4 h-4" style={{ color: colors.blue }} />
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-app antialiased" style={{ backgroundColor: colors.background }}>
|
||||
<div className="max-w-7xl mx-auto px-4 py-8">
|
||||
{/* Header */}
|
||||
<div className="mb-8">
|
||||
<h1 className="text-4xl font-bold mb-2" style={{ color: colors.brightWhite }}>
|
||||
Minecraft Plugin Store
|
||||
</h1>
|
||||
<p className="text-lg" style={{ color: colors.foreground }}>
|
||||
Browse and discover plugins from Modrinth
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Search and Filters */}
|
||||
<div className="mb-6 space-y-4">
|
||||
<form onSubmit={handleSearch} className="flex gap-4">
|
||||
<div className="flex-1 relative">
|
||||
<Search className="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5" style={{ color: colors.foreground }} />
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
placeholder="Search plugins..."
|
||||
className="w-full pl-12 pr-4 py-3 rounded-xl border focus:outline-none transition-all"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
borderColor: colors.brightBlack,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="px-6 py-3 rounded-xl font-medium transition-all hover:scale-105 border"
|
||||
style={{
|
||||
backgroundColor: colors.blue,
|
||||
borderColor: colors.blue,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
Search
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="flex gap-4 flex-wrap">
|
||||
<div className="w-48">
|
||||
<Dropdown
|
||||
value={selectedGameVersion}
|
||||
options={gameVersions}
|
||||
onChange={(value) => {
|
||||
setSelectedGameVersion(value);
|
||||
setCurrentPage(0);
|
||||
}}
|
||||
placeholder="All Versions"
|
||||
icon={Filter}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{error && (
|
||||
<div className="mb-6 p-4 rounded-xl border" style={{ backgroundColor: `${colors.red}20`, borderColor: colors.red }}>
|
||||
<p style={{ color: colors.brightRed }}>{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Loading State */}
|
||||
{loading && (
|
||||
<div className="flex justify-center items-center py-12">
|
||||
<div className="w-8 h-8 border-4 border-current border-t-transparent rounded-full animate-spin" style={{ color: colors.blue }} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Plugin Grid */}
|
||||
{!loading && plugins.length > 0 && (
|
||||
<>
|
||||
<div className="mb-4">
|
||||
<p style={{ color: colors.foreground }}>
|
||||
Found {totalResults} plugin{totalResults !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{plugins.map((plugin) => (
|
||||
<div
|
||||
key={plugin.project_id}
|
||||
onClick={() => handlePluginClick(plugin.project_id)}
|
||||
className="rounded-xl border p-6 cursor-pointer transition-all hover:scale-105 hover:shadow-lg"
|
||||
style={{
|
||||
backgroundColor: colors.backgroundSecondary,
|
||||
borderColor: colors.brightBlack
|
||||
}}
|
||||
>
|
||||
<div className="flex items-start gap-4 mb-4">
|
||||
{plugin.icon_url ? (
|
||||
<img
|
||||
src={plugin.icon_url}
|
||||
alt={plugin.title}
|
||||
className="w-16 h-16 rounded-lg object-cover flex-shrink-0"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className="w-16 h-16 rounded-lg flex items-center justify-center flex-shrink-0"
|
||||
style={{ backgroundColor: colors.brightBlack }}
|
||||
>
|
||||
<Package className="w-8 h-8" style={{ color: colors.foreground }} />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="text-lg font-semibold mb-1 truncate" style={{ color: colors.brightWhite }}>
|
||||
{plugin.title}
|
||||
</h3>
|
||||
<p className="text-sm truncate" style={{ color: colors.foreground }}>
|
||||
by {plugin.author}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-sm mb-4 line-clamp-3" style={{ color: colors.foreground }}>
|
||||
{truncateDescription(plugin.description)}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex items-center gap-1">
|
||||
<Download className="w-4 h-4" style={{ color: colors.blue }} />
|
||||
<span style={{ color: colors.foreground }}>{plugin.downloads?.toLocaleString() || 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-4 h-4" style={{ color: colors.foreground }} />
|
||||
<span style={{ color: colors.foreground }}>{formatDate(plugin.date_modified)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{plugin.loaders && plugin.loaders.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{plugin.loaders.slice(0, 3).map((loader) => (
|
||||
<span
|
||||
key={loader}
|
||||
className="px-2 py-1 rounded text-xs"
|
||||
style={{ backgroundColor: colors.brightBlack, color: colors.foreground }}
|
||||
>
|
||||
{loader}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalResults > 20 && (
|
||||
<div className="mt-8 flex justify-center gap-4">
|
||||
<button
|
||||
onClick={() => setCurrentPage(Math.max(0, currentPage - 1))}
|
||||
disabled={currentPage === 0}
|
||||
className="px-4 py-2 rounded-xl border transition-all disabled:opacity-50"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
borderColor: colors.brightBlack,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
Previous
|
||||
</button>
|
||||
<span className="px-4 py-2" style={{ color: colors.foreground }}>
|
||||
Page {currentPage + 1} of {Math.ceil(totalResults / 20)}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setCurrentPage(currentPage + 1)}
|
||||
disabled={(currentPage + 1) * 20 >= totalResults}
|
||||
className="px-4 py-2 rounded-xl border transition-all disabled:opacity-50"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
borderColor: colors.brightBlack,
|
||||
color: colors.brightWhite
|
||||
}}
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Empty State */}
|
||||
{!loading && plugins.length === 0 && !error && (
|
||||
<div className="text-center py-12">
|
||||
<Package className="w-16 h-16 mx-auto mb-4" style={{ color: colors.foreground }} />
|
||||
<p className="text-lg" style={{ color: colors.foreground }}>
|
||||
No plugins found. Try adjusting your search or filters.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PluginStore;
|
||||
@@ -0,0 +1,401 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Search, Download, RefreshCw, Package, AlertTriangle, ArrowLeft, Filter
|
||||
} from "lucide-react";
|
||||
import { colors, Dropdown, SectionCard, minecraftVersions } from '../../components/DashboardComponents';
|
||||
|
||||
import { API_BASE_URL } from '../../config/api';
|
||||
|
||||
// Embedded Plugin Store Component for Dashboard
|
||||
const PluginStoreEmbedded = ({ serverId }) => {
|
||||
const [plugins, setPlugins] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedGameVersion, setSelectedGameVersion] = useState('');
|
||||
const [currentPage, setCurrentPage] = useState(0);
|
||||
const [error, setError] = useState('');
|
||||
const [selectedPlugin, setSelectedPlugin] = useState(null);
|
||||
const [pluginDetails, setPluginDetails] = useState(null);
|
||||
const [pluginVersions, setPluginVersions] = useState([]);
|
||||
const [selectedVersion, setSelectedVersion] = useState(null);
|
||||
const [downloadingToServer, setDownloadingToServer] = useState(false);
|
||||
const [downloadStatus, setDownloadStatus] = useState('');
|
||||
const [loadingDetails, setLoadingDetails] = useState(false);
|
||||
const [totalResults, setTotalResults] = useState(0);
|
||||
|
||||
const handlePluginClick = async (pluginId) => {
|
||||
setSelectedPlugin(pluginId);
|
||||
setError('');
|
||||
setLoadingDetails(true);
|
||||
|
||||
try {
|
||||
// Fetch plugin details
|
||||
const projectResponse = await fetch(
|
||||
`${API_BASE_URL}/api/modrinth/project/${pluginId}`,
|
||||
{
|
||||
headers: {
|
||||
'User-Agent': 'AnchorHost/1.0'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!projectResponse.ok) {
|
||||
throw new Error('Failed to fetch plugin details');
|
||||
}
|
||||
|
||||
const projectData = await projectResponse.json();
|
||||
setPluginDetails(projectData);
|
||||
|
||||
// Fetch versions
|
||||
const versionsResponse = await fetch(
|
||||
`${API_BASE_URL}/api/modrinth/project/${pluginId}/versions`
|
||||
);
|
||||
|
||||
if (versionsResponse.ok) {
|
||||
const versionsData = await versionsResponse.json();
|
||||
setPluginVersions(versionsData);
|
||||
if (versionsData.length > 0) {
|
||||
setSelectedVersion(versionsData[0]);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
console.error('Error fetching plugin details:', err);
|
||||
} finally {
|
||||
setLoadingDetails(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBackToList = () => {
|
||||
setSelectedPlugin(null);
|
||||
setPluginDetails(null);
|
||||
setPluginVersions([]);
|
||||
setSelectedVersion(null);
|
||||
setError('');
|
||||
};
|
||||
|
||||
const handleDownloadToServer = async () => {
|
||||
if (!serverId || !selectedVersion) {
|
||||
setError('Please select a version first');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedVersion.files || selectedVersion.files.length === 0) {
|
||||
setError('No file available for this version');
|
||||
return;
|
||||
}
|
||||
|
||||
const primaryFile = selectedVersion.files.find(f => f.primary) || selectedVersion.files[0];
|
||||
setDownloadingToServer(true);
|
||||
setDownloadStatus('Downloading plugin...');
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem('anchorhost_token');
|
||||
if (!token) {
|
||||
throw new Error('Not authenticated');
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/plugins/download-to-server`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
server_id: serverId,
|
||||
plugin_url: primaryFile.url,
|
||||
plugin_name: pluginDetails?.title || selectedPlugin,
|
||||
file_name: primaryFile.filename || `${selectedPlugin}.jar`
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || 'Failed to download plugin to server');
|
||||
}
|
||||
|
||||
setDownloadStatus('Plugin downloaded successfully!');
|
||||
setTimeout(() => {
|
||||
setDownloadStatus('');
|
||||
setDownloadingToServer(false);
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
setDownloadingToServer(false);
|
||||
setDownloadStatus('');
|
||||
}
|
||||
};
|
||||
|
||||
const gameVersions = [
|
||||
{ value: '', label: 'All Versions' },
|
||||
...minecraftVersions.flatMap(series =>
|
||||
series.versions.map(v => ({ value: v, label: v }))
|
||||
)
|
||||
];
|
||||
|
||||
const searchPlugins = useCallback(async (query = '', page = 0) => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
query: query || '',
|
||||
limit: '20',
|
||||
offset: (page * 20).toString(),
|
||||
project_type: 'plugin'
|
||||
});
|
||||
|
||||
if (selectedGameVersion) {
|
||||
params.append('game_versions', selectedGameVersion);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/modrinth/search?${params.toString()}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to search plugins');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setPlugins(data.hits || []);
|
||||
setTotalResults(data.total_hits || 0);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
console.error('Error searching plugins:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [selectedGameVersion]);
|
||||
|
||||
useEffect(() => {
|
||||
searchPlugins(searchQuery, currentPage);
|
||||
}, [searchPlugins, searchQuery, currentPage]);
|
||||
|
||||
const handleSearch = (e) => {
|
||||
e.preventDefault();
|
||||
setCurrentPage(0);
|
||||
searchPlugins(searchQuery, 0);
|
||||
};
|
||||
|
||||
if (loadingDetails) {
|
||||
return (
|
||||
<div className="h-full flex justify-center items-center rounded-2xl animate-pulse" style={{ backgroundColor: 'rgba(0,0,0,0.1)' }}>
|
||||
<RefreshCw className="w-8 h-8 animate-spin text-blue-500" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (selectedPlugin && pluginDetails) {
|
||||
return (
|
||||
<div className="h-full flex flex-col space-y-8 animate-in fade-in slide-in-from-right-4 duration-300">
|
||||
<div className="flex items-center justify-between">
|
||||
<button
|
||||
onClick={handleBackToList}
|
||||
className="flex items-center space-x-2 text-xs font-bold uppercase tracking-wider px-5 py-2.5 rounded-xl transition-all duration-200 hover:scale-105 border hover:bg-white/10"
|
||||
style={{ color: colors.foreground, backgroundColor: colors.brightBlack, borderColor: colors.brightBlack }}
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4" />
|
||||
<span>Back to Store</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<SectionCard title={pluginDetails.title} icon={Package} color={colors.blue}>
|
||||
<div className="flex flex-col md:flex-row items-center md:items-start gap-8">
|
||||
<img
|
||||
src={pluginDetails.icon_url || 'https://via.placeholder.com/150'}
|
||||
alt={pluginDetails.title}
|
||||
className="w-32 h-32 rounded-3xl shadow-2xl border-4 border-white/5"
|
||||
/>
|
||||
<div className="flex-1 text-center md:text-left">
|
||||
<p className="text-base mb-6 leading-relaxed opacity-70" style={{ color: colors.foreground }}>{pluginDetails.description}</p>
|
||||
<div className="flex flex-wrap justify-center md:justify-start items-center gap-4 text-xs">
|
||||
<div className="px-4 py-2.5 rounded-xl border flex flex-col items-center justify-center min-w-[100px]" style={{ backgroundColor: colors.brightBlack, borderColor: colors.brightBlack }}>
|
||||
<span className="text-[10px] uppercase opacity-50 mb-1">Downloads</span>
|
||||
<span className="font-bold text-sm" style={{ color: colors.blue }}>{pluginDetails.downloads.toLocaleString()}</span>
|
||||
</div>
|
||||
<div className="px-4 py-2.5 rounded-xl border flex flex-col items-center justify-center min-w-[100px]" style={{ backgroundColor: colors.brightBlack, borderColor: colors.brightBlack }}>
|
||||
<span className="text-[10px] uppercase opacity-50 mb-1">Last Update</span>
|
||||
<span className="font-bold text-sm" style={{ color: colors.green }}>{new Date(pluginDetails.updated).toLocaleDateString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SectionCard>
|
||||
|
||||
<SectionCard title="Available Versions" icon={Download} color={colors.green}>
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
{pluginVersions.map((version) => (
|
||||
<div
|
||||
key={version.id}
|
||||
onClick={() => setSelectedVersion(version)}
|
||||
className={`p-5 rounded-2xl border transition-all duration-300 group cursor-pointer ${
|
||||
selectedVersion?.id === version.id
|
||||
? 'bg-blue-500/10'
|
||||
: 'bg-black/20 hover:bg-white/5'
|
||||
}`}
|
||||
style={{ borderColor: selectedVersion?.id === version.id ? colors.blue : colors.brightBlack }}
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-1">
|
||||
<span className="font-bold text-white text-base">{version.name}</span>
|
||||
<span className="px-2 py-0.5 rounded text-[10px] font-bold bg-white/10 text-white/60">
|
||||
{version.version_number}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{version.game_versions.slice(0, 5).map(gv => (
|
||||
<span key={gv} className="text-[10px] px-2 py-0.5 rounded bg-black/40 text-blue-400 border border-blue-500/10">
|
||||
{gv}
|
||||
</span>
|
||||
))}
|
||||
{version.game_versions.length > 5 && <span className="text-[10px] opacity-40">+{version.game_versions.length - 5} more</span>}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setSelectedVersion(version);
|
||||
handleDownloadToServer();
|
||||
}}
|
||||
disabled={downloadingToServer}
|
||||
className={`ml-4 px-6 py-3 rounded-xl font-bold transition-all text-xs uppercase tracking-wider border flex items-center gap-2 ${
|
||||
selectedVersion?.id === version.id
|
||||
? 'bg-blue-500/20 text-blue-400 border-blue-500/30 hover:bg-blue-500/30'
|
||||
: 'bg-white/5 text-white/60 border-transparent hover:bg-white/10 hover:text-white'
|
||||
} disabled:opacity-50`}
|
||||
>
|
||||
{downloadingToServer && selectedVersion?.id === version.id ? (
|
||||
<>
|
||||
<RefreshCw className="w-4 h-4 animate-spin" />
|
||||
<span>Installing...</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="w-4 h-4" />
|
||||
<span>Install</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</SectionCard>
|
||||
|
||||
{downloadStatus && (
|
||||
<div className="p-4 rounded-2xl bg-green-500/10 border border-green-500/20 text-green-400 text-sm font-bold flex items-center justify-center gap-3 animate-in fade-in slide-in-from-bottom-2">
|
||||
<div className="w-2 h-2 rounded-full bg-green-500 animate-pulse" />
|
||||
{downloadStatus}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-300">
|
||||
<SectionCard title="Search Plugins" icon={Search} color={colors.blue}>
|
||||
<div className="flex flex-col lg:flex-row gap-4">
|
||||
<div className="flex-1 relative group">
|
||||
<Search className="w-4 h-4 absolute left-4 top-1/2 transform -translate-y-1/2 text-white/50 group-focus-within:text-blue-400 transition-colors" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search thousands of plugins..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleSearch(e)}
|
||||
className="w-full pl-11 pr-4 py-3 rounded-xl bg-black/40 border text-white placeholder:text-white/50 focus:border-primary/50 focus:bg-black/60 focus:outline-none transition-all font-medium text-sm"
|
||||
style={{ borderColor: colors.brightBlack }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<div className="w-48">
|
||||
<Dropdown
|
||||
value={selectedGameVersion}
|
||||
options={gameVersions}
|
||||
onChange={setSelectedGameVersion}
|
||||
placeholder="Version"
|
||||
icon={Filter}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SectionCard>
|
||||
|
||||
<div className="flex-1 overflow-y-auto pr-2 custom-scrollbar">
|
||||
{loading ? (
|
||||
<div className="flex flex-col justify-center items-center h-64 space-y-4 opacity-50">
|
||||
<RefreshCw className="w-10 h-10 animate-spin text-blue-500" />
|
||||
<span className="text-sm font-bold tracking-widest text-blue-400 animate-pulse uppercase">Searching Modrinth...</span>
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="text-center p-12 bg-red-500/5 border border-red-500/10 rounded-3xl">
|
||||
<AlertTriangle className="w-16 h-16 mx-auto mb-4 text-red-500 opacity-50" />
|
||||
<h4 className="text-xl font-bold text-white mb-2">Search Error</h4>
|
||||
<p className="text-red-400/70">{error}</p>
|
||||
</div>
|
||||
) : plugins.length === 0 ? (
|
||||
<div className="text-center p-12 bg-white/5 border border-dashed border-white/10 rounded-3xl">
|
||||
<Package className="w-16 h-16 mx-auto mb-4 opacity-20" />
|
||||
<h4 className="text-xl font-bold text-white/40 mb-2">No Plugins Found</h4>
|
||||
<p className="text-white/20 text-sm">Try broadening your search or changing the version filter.</p>
|
||||
</div>
|
||||
) : (
|
||||
<SectionCard title={`Results (${totalResults.toLocaleString()})`} icon={Package} color={colors.magenta}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
{plugins.map((plugin) => (
|
||||
<div
|
||||
key={plugin.slug}
|
||||
onClick={() => handlePluginClick(plugin.slug)}
|
||||
className="p-5 rounded-xl border transition-all cursor-pointer group flex flex-col h-full"
|
||||
style={{ backgroundColor: colors.brightBlack, borderColor: colors.brightBlack }}
|
||||
>
|
||||
<div className="flex items-start gap-4 mb-4">
|
||||
<div className="relative">
|
||||
<img
|
||||
src={plugin.icon_url || 'https://via.placeholder.com/64'}
|
||||
alt={plugin.title}
|
||||
className="w-16 h-16 rounded-xl shadow-lg group-hover:scale-110 transition-transform duration-500 relative z-10 bg-gray-900 border border-white/5"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-blue-500/20 blur-xl rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-500" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-bold text-white text-base leading-tight group-hover:text-blue-400 transition-colors truncate">
|
||||
{plugin.title}
|
||||
</h4>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<span className="text-[10px] font-bold text-white/40 uppercase tracking-tighter">
|
||||
{plugin.author}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-white/70 mb-6 line-clamp-2 leading-relaxed flex-1">
|
||||
{plugin.description}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center justify-between pt-4 border-t border-white/5 mt-auto">
|
||||
<div className="flex items-center gap-3 text-[10px] font-bold text-white/30 uppercase tracking-wider">
|
||||
<span className="flex items-center gap-1.5 px-2 py-1 rounded bg-black/40">
|
||||
<Download className="w-3 h-3 text-blue-500" />
|
||||
{plugin.downloads.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="p-1.5 rounded-lg bg-white/5 group-hover:bg-blue-500/20 group-hover:text-blue-400 transition-all">
|
||||
<ArrowLeft className="w-3.5 h-3.5 rotate-180" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</SectionCard>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PluginStoreEmbedded;
|
||||
Reference in new issue
Block a user