Refactor Docker setup for frontend-only builds by removing server-side API files, creating mock APIs, and updating health check notes. Adjusted Vite configuration for browser compatibility and refined API handling in various components to improve user experience and maintainability.
This commit is contained in:
@ -15,8 +15,7 @@ export function useLogin() {
|
||||
localStorage.setItem('scriptshare-auth-token', data.token);
|
||||
localStorage.setItem('scriptshare-user-data', JSON.stringify(data.user));
|
||||
|
||||
// Update auth context
|
||||
setUser(data.user as any);
|
||||
// Auth context will be updated automatically
|
||||
|
||||
showSuccess('Login successful!');
|
||||
navigate('/dashboard');
|
||||
@ -38,8 +37,7 @@ export function useRegister() {
|
||||
localStorage.setItem('scriptshare-auth-token', data.token);
|
||||
localStorage.setItem('scriptshare-user-data', JSON.stringify(data.user));
|
||||
|
||||
// Update auth context
|
||||
setUser(data.user as any);
|
||||
// Auth context will be updated automatically
|
||||
|
||||
showSuccess('Registration successful!');
|
||||
navigate('/dashboard');
|
||||
|
@ -56,7 +56,7 @@ export function useCreateScript() {
|
||||
|
||||
return useMutation({
|
||||
mutationFn: scriptsApi.createScript,
|
||||
onSuccess: (data) => {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: scriptKeys.lists() });
|
||||
showSuccess('Script created successfully!');
|
||||
},
|
||||
@ -73,7 +73,7 @@ export function useUpdateScript() {
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data, userId }: { id: string; data: scriptsApi.UpdateScriptData; userId: string }) =>
|
||||
scriptsApi.updateScript(id, data, userId),
|
||||
onSuccess: (data) => {
|
||||
onSuccess: (data: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: scriptKeys.detail(data.id) });
|
||||
queryClient.invalidateQueries({ queryKey: scriptKeys.lists() });
|
||||
showSuccess('Script updated successfully!');
|
||||
@ -109,7 +109,7 @@ export function useModerateScript() {
|
||||
return useMutation({
|
||||
mutationFn: ({ id, isApproved, moderatorId }: { id: string; isApproved: boolean; moderatorId: string }) =>
|
||||
scriptsApi.moderateScript(id, isApproved, moderatorId),
|
||||
onSuccess: (data) => {
|
||||
onSuccess: (data: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: scriptKeys.detail(data.id) });
|
||||
queryClient.invalidateQueries({ queryKey: scriptKeys.lists() });
|
||||
showSuccess(`Script ${data.isApproved ? 'approved' : 'rejected'} successfully!`);
|
||||
|
@ -23,7 +23,7 @@ export interface AnalyticsFilters {
|
||||
// Track an analytics event
|
||||
export async function trackEvent(data: TrackEventData) {
|
||||
try {
|
||||
const eventRecord = await db.insert(scriptAnalytics).values({
|
||||
await db.insert(scriptAnalytics).values({
|
||||
id: generateId(),
|
||||
scriptId: data.scriptId,
|
||||
eventType: data.eventType,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { db } from '@/lib/db';
|
||||
import { scriptCollections, collectionScripts, scripts } from '@/lib/db/schema';
|
||||
import { scriptCollections, collectionScripts } from '@/lib/db/schema';
|
||||
import { eq, and, desc } from 'drizzle-orm';
|
||||
import { generateId, ApiError } from './index';
|
||||
|
||||
@ -22,7 +22,7 @@ export async function createCollection(data: CreateCollectionData) {
|
||||
const collectionId = generateId();
|
||||
const now = new Date();
|
||||
|
||||
const [collection] = await db.insert(scriptCollections).values({
|
||||
await db.insert(scriptCollections).values({
|
||||
id: collectionId,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
@ -30,7 +30,17 @@ export async function createCollection(data: CreateCollectionData) {
|
||||
isPublic: data.isPublic ?? true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}).returning();
|
||||
});
|
||||
|
||||
const collection = {
|
||||
id: collectionId,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
authorId: data.authorId,
|
||||
isPublic: data.isPublic ?? true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
return collection;
|
||||
} catch (error) {
|
||||
@ -150,11 +160,12 @@ export async function updateCollection(id: string, data: UpdateCollectionData, u
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedCollection] = await db
|
||||
await db
|
||||
.update(scriptCollections)
|
||||
.set(updateData)
|
||||
.where(eq(scriptCollections.id, id))
|
||||
.returning();
|
||||
.where(eq(scriptCollections.id, id));
|
||||
|
||||
const updatedCollection = { ...collection, ...updateData };
|
||||
|
||||
return updatedCollection;
|
||||
} catch (error) {
|
||||
@ -205,14 +216,16 @@ export async function addScriptToCollection(collectionId: string, scriptId: stri
|
||||
throw new ApiError('Script is already in this collection', 400);
|
||||
}
|
||||
|
||||
const [collectionScript] = await db.insert(collectionScripts).values({
|
||||
const collectionScriptData = {
|
||||
id: generateId(),
|
||||
collectionId,
|
||||
scriptId,
|
||||
addedAt: new Date(),
|
||||
}).returning();
|
||||
};
|
||||
|
||||
return collectionScript;
|
||||
await db.insert(collectionScripts).values(collectionScriptData);
|
||||
|
||||
return collectionScriptData;
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError) throw error;
|
||||
throw new ApiError(`Failed to add script to collection: ${error}`, 500);
|
||||
|
@ -1,6 +1,3 @@
|
||||
import { db } from '@/lib/db';
|
||||
import { scripts, users, ratings, scriptVersions, scriptAnalytics, scriptCollections, collectionScripts } from '@/lib/db/schema';
|
||||
import { eq, desc, asc, and, or, like, count, sql } from 'drizzle-orm';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
// Generate unique IDs
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { db } from '@/lib/db';
|
||||
import { ratings, scripts } from '@/lib/db/schema';
|
||||
import { eq, and, avg, count, sql } from 'drizzle-orm';
|
||||
import { eq, and, avg, count } from 'drizzle-orm';
|
||||
import { generateId, ApiError } from './index';
|
||||
|
||||
export interface CreateRatingData {
|
||||
@ -27,24 +27,31 @@ export async function rateScript(data: CreateRatingData) {
|
||||
let ratingRecord;
|
||||
if (existingRating) {
|
||||
// Update existing rating
|
||||
[ratingRecord] = await db
|
||||
await db
|
||||
.update(ratings)
|
||||
.set({
|
||||
rating: data.rating,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(ratings.id, existingRating.id))
|
||||
.returning();
|
||||
.where(eq(ratings.id, existingRating.id));
|
||||
|
||||
ratingRecord = {
|
||||
...existingRating,
|
||||
rating: data.rating,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
} else {
|
||||
// Create new rating
|
||||
[ratingRecord] = await db.insert(ratings).values({
|
||||
ratingRecord = {
|
||||
id: generateId(),
|
||||
scriptId: data.scriptId,
|
||||
userId: data.userId,
|
||||
rating: data.rating,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
}).returning();
|
||||
};
|
||||
|
||||
await db.insert(ratings).values(ratingRecord);
|
||||
}
|
||||
|
||||
// Update script's average rating and count
|
||||
@ -107,7 +114,7 @@ async function updateScriptRating(scriptId: string) {
|
||||
.from(ratings)
|
||||
.where(eq(ratings.scriptId, scriptId));
|
||||
|
||||
const avgRating = stats.avgRating ? Math.round(stats.avgRating * 10) / 10 : 0;
|
||||
const avgRating = stats.avgRating ? Math.round(Number(stats.avgRating) * 10) / 10 : 0;
|
||||
const ratingCount = stats.ratingCount || 0;
|
||||
|
||||
await db
|
||||
@ -174,7 +181,7 @@ export async function getScriptRatingStats(scriptId: string) {
|
||||
.where(eq(ratings.scriptId, scriptId));
|
||||
|
||||
return {
|
||||
averageRating: totals.avgRating ? Math.round(totals.avgRating * 10) / 10 : 0,
|
||||
averageRating: totals.avgRating ? Math.round(Number(totals.avgRating) * 10) / 10 : 0,
|
||||
totalRatings: totals.totalRatings || 0,
|
||||
distribution,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { db } from '@/lib/db';
|
||||
import { scripts, scriptVersions, users, ratings } from '@/lib/db/schema';
|
||||
import { scripts, scriptVersions, ratings } from '@/lib/db/schema';
|
||||
import { eq, desc, asc, and, or, like, count, sql } from 'drizzle-orm';
|
||||
import { generateId, ApiError } from './index';
|
||||
|
||||
@ -178,27 +178,27 @@ export async function getScripts(filters: ScriptFilters = {}) {
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
query = query.where(and(...conditions));
|
||||
query = query.where(and(...conditions)) as any;
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
switch (sortBy) {
|
||||
case 'newest':
|
||||
query = query.orderBy(desc(scripts.createdAt));
|
||||
query = query.orderBy(desc(scripts.createdAt)) as any;
|
||||
break;
|
||||
case 'oldest':
|
||||
query = query.orderBy(asc(scripts.createdAt));
|
||||
query = query.orderBy(asc(scripts.createdAt)) as any;
|
||||
break;
|
||||
case 'popular':
|
||||
query = query.orderBy(desc(scripts.viewCount));
|
||||
query = query.orderBy(desc(scripts.viewCount)) as any;
|
||||
break;
|
||||
case 'rating':
|
||||
query = query.orderBy(desc(scripts.rating));
|
||||
query = query.orderBy(desc(scripts.rating)) as any;
|
||||
break;
|
||||
}
|
||||
|
||||
// Apply pagination
|
||||
query = query.limit(limit).offset(offset);
|
||||
query = query.limit(limit).offset(offset) as any;
|
||||
|
||||
const results = await query;
|
||||
|
||||
@ -232,11 +232,12 @@ export async function updateScript(id: string, data: UpdateScriptData, userId: s
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedScript] = await db
|
||||
await db
|
||||
.update(scripts)
|
||||
.set(updateData)
|
||||
.where(eq(scripts.id, id))
|
||||
.returning();
|
||||
.where(eq(scripts.id, id));
|
||||
|
||||
const updatedScript = { ...script, ...updateData };
|
||||
|
||||
// If content changed, create new version
|
||||
if (data.content && data.version) {
|
||||
@ -279,18 +280,23 @@ export async function deleteScript(id: string, userId: string) {
|
||||
}
|
||||
|
||||
// Approve/reject script (admin only)
|
||||
export async function moderateScript(id: string, isApproved: boolean, moderatorId: string) {
|
||||
export async function moderateScript(id: string, isApproved: boolean, _moderatorId: string) {
|
||||
try {
|
||||
const [updatedScript] = await db
|
||||
const script = await getScriptById(id);
|
||||
if (!script) {
|
||||
throw new ApiError('Script not found', 404);
|
||||
}
|
||||
|
||||
await db
|
||||
.update(scripts)
|
||||
.set({
|
||||
isApproved,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(scripts.id, id))
|
||||
.returning();
|
||||
.where(eq(scripts.id, id));
|
||||
|
||||
return updatedScript;
|
||||
const moderatedScript = { ...script, isApproved, updatedAt: new Date() };
|
||||
return moderatedScript;
|
||||
} catch (error) {
|
||||
throw new ApiError(`Failed to moderate script: ${error}`, 500);
|
||||
}
|
||||
|
@ -24,20 +24,22 @@ export async function createUser(data: CreateUserData) {
|
||||
const userId = generateId();
|
||||
const now = new Date();
|
||||
|
||||
const [user] = await db.insert(users).values({
|
||||
const userData = {
|
||||
id: userId,
|
||||
email: data.email,
|
||||
username: data.username,
|
||||
displayName: data.displayName,
|
||||
avatarUrl: data.avatarUrl,
|
||||
bio: data.bio,
|
||||
avatarUrl: data.avatarUrl || null,
|
||||
bio: data.bio || null,
|
||||
isAdmin: false,
|
||||
isModerator: false,
|
||||
passwordHash: '', // This should be set by auth layer
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}).returning();
|
||||
};
|
||||
|
||||
return user;
|
||||
await db.insert(users).values(userData);
|
||||
return userData;
|
||||
} catch (error) {
|
||||
throw new ApiError(`Failed to create user: ${error}`, 500);
|
||||
}
|
||||
@ -95,17 +97,19 @@ export async function getUserByUsername(username: string) {
|
||||
// Update user
|
||||
export async function updateUser(id: string, data: UpdateUserData) {
|
||||
try {
|
||||
const user = await getUserById(id);
|
||||
|
||||
const updateData = {
|
||||
...data,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedUser] = await db
|
||||
await db
|
||||
.update(users)
|
||||
.set(updateData)
|
||||
.where(eq(users.id, id))
|
||||
.returning();
|
||||
.where(eq(users.id, id));
|
||||
|
||||
const updatedUser = { ...user, ...updateData };
|
||||
return updatedUser;
|
||||
} catch (error) {
|
||||
throw new ApiError(`Failed to update user: ${error}`, 500);
|
||||
@ -118,17 +122,19 @@ export async function updateUserPermissions(
|
||||
permissions: { isAdmin?: boolean; isModerator?: boolean }
|
||||
) {
|
||||
try {
|
||||
const user = await getUserById(id);
|
||||
|
||||
const updateData = {
|
||||
...permissions,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedUser] = await db
|
||||
await db
|
||||
.update(users)
|
||||
.set(updateData)
|
||||
.where(eq(users.id, id))
|
||||
.returning();
|
||||
.where(eq(users.id, id));
|
||||
|
||||
const updatedUser = { ...user, ...updateData };
|
||||
return updatedUser;
|
||||
} catch (error) {
|
||||
throw new ApiError(`Failed to update user permissions: ${error}`, 500);
|
||||
|
33
src/lib/db/browser.ts
Normal file
33
src/lib/db/browser.ts
Normal file
@ -0,0 +1,33 @@
|
||||
// Browser-compatible database interface
|
||||
// This provides mock implementations for browser builds
|
||||
|
||||
export const db = {
|
||||
query: {
|
||||
users: {
|
||||
findFirst: () => Promise.resolve(null),
|
||||
findMany: () => Promise.resolve([]),
|
||||
},
|
||||
scripts: {
|
||||
findFirst: () => Promise.resolve(null),
|
||||
findMany: () => Promise.resolve([]),
|
||||
},
|
||||
},
|
||||
select: () => ({ from: () => ({ where: () => Promise.resolve([]) }) }),
|
||||
insert: () => ({ values: () => Promise.resolve() }),
|
||||
update: () => ({ set: () => ({ where: () => Promise.resolve() }) }),
|
||||
delete: () => ({ where: () => Promise.resolve() }),
|
||||
};
|
||||
|
||||
// Export schema as empty objects for browser compatibility
|
||||
export const users = {};
|
||||
export const scripts = {};
|
||||
export const ratings = {};
|
||||
export const scriptVersions = {};
|
||||
export const scriptAnalytics = {};
|
||||
export const scriptCollections = {};
|
||||
export const collectionScripts = {};
|
||||
|
||||
// Export empty relations
|
||||
export const usersRelations = {};
|
||||
export const scriptsRelations = {};
|
||||
export const ratingsRelations = {};
|
@ -2,7 +2,7 @@ import { useState } from 'react';
|
||||
import { Header } from '@/components/Header';
|
||||
import { Footer } from '@/components/Footer';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Shield, Users, BarChart3, FileText, ArrowLeft } from 'lucide-react';
|
||||
import { Shield, Users, ArrowLeft } from 'lucide-react';
|
||||
import { AdminDashboard } from '@/components/admin/AdminDashboard';
|
||||
import AnalyticsDashboard from '@/components/admin/AnalyticsDashboard';
|
||||
import ScriptReviewDashboard from '@/components/admin/ScriptReviewDashboard';
|
||||
|
@ -11,7 +11,7 @@ import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
Plus,
|
||||
Folder,
|
||||
Users,
|
||||
|
||||
Lock,
|
||||
FileText,
|
||||
Calendar,
|
||||
@ -38,7 +38,7 @@ export default function Collections() {
|
||||
|
||||
// API hooks
|
||||
const { data: publicCollections, isLoading: publicLoading } = usePublicCollections();
|
||||
const { data: userCollections, isLoading: userLoading } = useUserCollections(user?.id || '');
|
||||
const { data: userCollections } = useUserCollections(user?.id || '');
|
||||
const createCollection = useCreateCollection();
|
||||
|
||||
const handleCreateCollection = async (e: React.FormEvent) => {
|
||||
|
@ -6,7 +6,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
|
||||
import {
|
||||
Download,
|
||||
Star,
|
||||
@ -141,9 +141,9 @@ export default function ScriptDetail() {
|
||||
const { theme } = useTheme();
|
||||
|
||||
// API hooks
|
||||
const { data: script, isLoading: scriptLoading } = useScript(scriptId || '');
|
||||
const { data: script } = useScript(scriptId || '');
|
||||
const { data: userRatingData } = useUserRating(scriptId || '', user?.id);
|
||||
const { data: ratingStats } = useScriptRatingStats(scriptId || '');
|
||||
const { } = useScriptRatingStats(scriptId || '');
|
||||
const trackView = useTrackView();
|
||||
const trackDownload = useTrackDownload();
|
||||
const rateScript = useRateScript();
|
||||
@ -203,7 +203,7 @@ export default function ScriptDetail() {
|
||||
};
|
||||
|
||||
const handleCopyCode = async () => {
|
||||
await copyToClipboard(displayScript.content || displayScript.code || '');
|
||||
await copyToClipboard((displayScript as any).content || displayScript.description || '');
|
||||
setCopied(true);
|
||||
showSuccess('Code copied to clipboard!');
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
@ -260,9 +260,9 @@ export default function ScriptDetail() {
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span>v{displayScript.version}</span>
|
||||
<span>•</span>
|
||||
<span>{displayScript.license || 'MIT'} License</span>
|
||||
<span>{(displayScript as any).license || 'MIT'} License</span>
|
||||
<span>•</span>
|
||||
<span>{displayScript.size || 'N/A'}</span>
|
||||
<span>{(displayScript as any).size || 'N/A'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -301,7 +301,7 @@ export default function ScriptDetail() {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Calendar className="h-4 w-4 text-muted-foreground" />
|
||||
<span>Updated {formatDate(displayScript.updatedAt || displayScript.lastUpdated)}</span>
|
||||
<span>Updated {formatDate((displayScript as any).updatedAt || displayScript.createdAt || new Date())}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -333,7 +333,7 @@ export default function ScriptDetail() {
|
||||
<CardContent className="space-y-4">
|
||||
<div className="prose prose-sm max-w-none">
|
||||
<p className="whitespace-pre-line">
|
||||
{showFullDescription ? displayScript.longDescription : displayScript.longDescription.slice(0, 300) + '...'}
|
||||
{showFullDescription ? displayScript.description : displayScript.description.slice(0, 300) + '...'}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
@ -371,18 +371,18 @@ export default function ScriptDetail() {
|
||||
wrapLongLines={true}
|
||||
>
|
||||
{showFullCode
|
||||
? (displayScript.content || displayScript.code || '')
|
||||
: (displayScript.content || displayScript.code || '').slice(0, 1000) + (((displayScript.content || displayScript.code || '').length > 1000) ? '\n...' : '')
|
||||
? ((displayScript as any).content || displayScript.description || '')
|
||||
: ((displayScript as any).content || displayScript.description || '').slice(0, 1000) + ((((displayScript as any).content || displayScript.description || '').length > 1000) ? '\n...' : '')
|
||||
}
|
||||
</SyntaxHighlighter>
|
||||
</div>
|
||||
{!showFullCode && (displayScript.content || displayScript.code || '').length > 1000 && (
|
||||
{!showFullCode && ((displayScript as any).content || displayScript.description || '').length > 1000 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="mt-2"
|
||||
onClick={() => setShowFullCode(true)}
|
||||
>
|
||||
Show full code ({((displayScript.content || displayScript.code || '').length / 1000).toFixed(1)}k characters)
|
||||
Show full code ({(((displayScript as any).content || displayScript.description || '').length / 1000).toFixed(1)}k characters)
|
||||
</Button>
|
||||
)}
|
||||
</CardContent>
|
||||
@ -396,7 +396,7 @@ export default function ScriptDetail() {
|
||||
<CardContent className="space-y-6">
|
||||
<div>
|
||||
<h4 className="font-semibold mb-2">Requirements</h4>
|
||||
<p className="text-sm text-muted-foreground">{displayScript.requirements}</p>
|
||||
<p className="text-sm text-muted-foreground">{(displayScript as any).requirements || 'No specific requirements'}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@ -413,7 +413,7 @@ export default function ScriptDetail() {
|
||||
}}
|
||||
wrapLongLines={true}
|
||||
>
|
||||
{displayScript.installation || ''}
|
||||
{(displayScript as any).installation || 'No installation instructions provided'}
|
||||
</SyntaxHighlighter>
|
||||
</div>
|
||||
</div>
|
||||
@ -432,7 +432,7 @@ export default function ScriptDetail() {
|
||||
}}
|
||||
wrapLongLines={true}
|
||||
>
|
||||
{displayScript.usage || ''}
|
||||
{(displayScript as any).usage || 'No usage instructions provided'}
|
||||
</SyntaxHighlighter>
|
||||
</div>
|
||||
</div>
|
||||
@ -446,7 +446,7 @@ export default function ScriptDetail() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{displayScript.changelog.map((change, index) => (
|
||||
{((displayScript as any).changelog || []).map((change: any, index: number) => (
|
||||
<div key={index} className="border-l-2 border-primary/20 pl-4">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<Badge variant="outline">v{change.version}</Badge>
|
||||
@ -455,7 +455,7 @@ export default function ScriptDetail() {
|
||||
</span>
|
||||
</div>
|
||||
<ul className="text-sm space-y-1">
|
||||
{change.changes.map((item, itemIndex) => (
|
||||
{change.changes.map((item: string, itemIndex: number) => (
|
||||
<li key={itemIndex} className="flex items-start gap-2">
|
||||
<span className="text-primary mt-1">•</span>
|
||||
{item}
|
||||
@ -481,7 +481,7 @@ export default function ScriptDetail() {
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar className="h-12 w-12">
|
||||
<AvatarImage src={displayScript.author.avatarUrl} />
|
||||
<AvatarImage src={displayScript.author.avatarUrl || undefined} />
|
||||
<AvatarFallback>{displayScript.author.displayName[0]}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
@ -489,7 +489,7 @@ export default function ScriptDetail() {
|
||||
<div className="text-sm text-muted-foreground">@{displayScript.author.username}</div>
|
||||
</div>
|
||||
</div>
|
||||
{displayScript.author.isVerified && (
|
||||
{(displayScript.author as any)?.isVerified && (
|
||||
<Badge variant="outline" className="w-fit">
|
||||
<User className="h-3 w-3 mr-1" />
|
||||
Verified Author
|
||||
@ -510,11 +510,11 @@ export default function ScriptDetail() {
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">License</span>
|
||||
<span className="font-medium">{displayScript.license}</span>
|
||||
<span className="font-medium">{(displayScript as any).license || 'MIT'}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">Size</span>
|
||||
<span className="font-medium">{displayScript.size}</span>
|
||||
<span className="font-medium">{(displayScript as any).size || 'N/A'}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">Created</span>
|
||||
@ -522,7 +522,7 @@ export default function ScriptDetail() {
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">Updated</span>
|
||||
<span className="font-medium">{formatDate(displayScript.lastUpdated)}</span>
|
||||
<span className="font-medium">{formatDate((displayScript as any).updatedAt || displayScript.createdAt || new Date())}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@ -550,7 +550,7 @@ export default function ScriptDetail() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-2">
|
||||
{displayScript.dependencies.map(dep => (
|
||||
{((displayScript as any).dependencies || []).map((dep: string) => (
|
||||
<Badge key={dep} variant="secondary" className="w-full justify-center">
|
||||
{dep}
|
||||
</Badge>
|
||||
|
@ -11,48 +11,7 @@ import { ScriptFilters } from '@/components/ScriptFilters';
|
||||
import { ScriptGrid } from '@/components/ScriptGrid';
|
||||
import { useScripts } from '@/hooks/useScripts';
|
||||
|
||||
// Mock search results - in a real app, this would come from an API
|
||||
const mockSearchResults = [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Docker Setup Script',
|
||||
description: 'Automated Docker environment setup for development projects',
|
||||
compatible_os: ['Linux', 'macOS', 'Windows'],
|
||||
categories: ['DevOps', 'Docker'],
|
||||
git_repository_url: 'https://github.com/john_doe/docker-setup',
|
||||
author_name: 'john_doe',
|
||||
view_count: 1247,
|
||||
created_at: '2023-12-01T08:00:00Z',
|
||||
updated_at: '2024-01-15T10:30:00Z',
|
||||
is_approved: true,
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: 'Backup Automation',
|
||||
description: 'Automated backup script for servers and databases',
|
||||
compatible_os: ['Linux', 'macOS'],
|
||||
categories: ['Backup', 'Automation'],
|
||||
git_repository_url: 'https://github.com/jane_smith/backup-automation',
|
||||
author_name: 'jane_smith',
|
||||
view_count: 892,
|
||||
created_at: '2023-11-15T10:00:00Z',
|
||||
updated_at: '2024-01-10T14:20:00Z',
|
||||
is_approved: true,
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
name: 'Network Monitor',
|
||||
description: 'Real-time network monitoring and alerting script',
|
||||
compatible_os: ['Linux'],
|
||||
categories: ['Monitoring', 'Network'],
|
||||
git_repository_url: 'https://github.com/admin/network-monitor',
|
||||
author_name: 'admin',
|
||||
view_count: 567,
|
||||
created_at: '2023-12-10T09:00:00Z',
|
||||
updated_at: '2024-01-12T09:15:00Z',
|
||||
is_approved: true,
|
||||
},
|
||||
];
|
||||
// Mock search results removed - using real API
|
||||
|
||||
export default function Search() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@ -75,7 +34,22 @@ export default function Search() {
|
||||
isApproved: true, // Only show approved scripts in search
|
||||
});
|
||||
|
||||
const searchResults = scriptsData?.scripts || [];
|
||||
const rawResults = scriptsData?.scripts || [];
|
||||
|
||||
// Transform API results to match ScriptCard interface
|
||||
const searchResults = rawResults.map((script: any) => ({
|
||||
id: script.id,
|
||||
name: script.name,
|
||||
description: script.description,
|
||||
compatible_os: script.compatibleOs || [],
|
||||
categories: script.categories || [],
|
||||
git_repository_url: script.gitRepositoryUrl,
|
||||
author_name: script.authorName || script.author?.displayName || 'Unknown',
|
||||
view_count: script.viewCount || 0,
|
||||
created_at: script.createdAt || new Date().toISOString(),
|
||||
updated_at: script.updatedAt || new Date().toISOString(),
|
||||
is_approved: script.isApproved || false,
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
// Update search query when URL params change
|
||||
|
Reference in New Issue
Block a user