Fix annotation types and author utils

This commit is contained in:
Damir Mukimov 2025-11-30 15:21:07 +01:00
parent 790d32cce0
commit bbbc1169b2
No known key found for this signature in database
GPG Key ID: 42996CC7C73BC750
5 changed files with 29 additions and 27 deletions

View File

@ -47,7 +47,7 @@ export function AnnotationSystem({
// Mock user data - in a real app this would come from auth // Mock user data - in a real app this would come from auth
const currentUser = { const currentUser = {
id: 1, id: "1",
name: "Anonymous", name: "Anonymous",
avatar: null, avatar: null,
}; };
@ -72,13 +72,13 @@ export function AnnotationSystem({
name: "Literary Scholar", name: "Literary Scholar",
avatar: undefined, avatar: undefined,
}, },
likes: 5,
liked: false,
content: content:
"This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.", "This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.",
type: "analysis", type: "analysis",
isOfficial: false, isOfficial: false,
createdAt: new Date(Date.now() - 1000000).toISOString(), createdAt: new Date(Date.now() - 1000000).toISOString(),
likes: 5,
liked: false,
}, },
{ {
id: "2", id: "2",
@ -90,13 +90,13 @@ export function AnnotationSystem({
name: "Translator", name: "Translator",
avatar: undefined, avatar: undefined,
}, },
likes: 3,
liked: false,
content: content:
"The original meaning in Russian contains a wordplay that is difficult to capture in English. A more literal translation might read as...", "The original meaning in Russian contains a wordplay that is difficult to capture in English. A more literal translation might read as...",
type: "translation", type: "translation",
isOfficial: false, isOfficial: false,
createdAt: new Date(Date.now() - 5000000).toISOString(), createdAt: new Date(Date.now() - 5000000).toISOString(),
likes: 3,
liked: false,
}, },
]; ];

View File

@ -27,16 +27,16 @@ export function AnnotationBrowser({
<CardHeader className="flex flex-row items-center gap-3 p-4"> <CardHeader className="flex flex-row items-center gap-3 p-4">
<Avatar> <Avatar>
<AvatarImage <AvatarImage
src={annotation.userAvatar || ""} src={annotation.user.avatar || ""}
alt={annotation.userName} alt={annotation.user.name}
/> />
<AvatarFallback> <AvatarFallback>
{annotation.userName.charAt(0).toUpperCase()} {annotation.user.name.charAt(0).toUpperCase()}
</AvatarFallback> </AvatarFallback>
</Avatar> </Avatar>
<div> <div>
<Heading level="h4" className="mb-1"> <Heading level="h4" className="mb-1">
{annotation.userName} {annotation.user.name}
</Heading> </Heading>
<Paragraph size="xs" variant="muted"> <Paragraph size="xs" variant="muted">
{new Date(annotation.createdAt).toLocaleString()} {new Date(annotation.createdAt).toLocaleString()}

View File

@ -101,12 +101,12 @@ export interface AuthorDisplayUtils {
/** /**
* Format numbers for display * Format numbers for display
*/ */
formatNumber: (num: number, format?: 'numbers' | 'abbreviated' | 'full') => string; formatNumber: (num: number | undefined, format?: 'numbers' | 'abbreviated' | 'full') => string;
/** /**
* Format rating for display * Format rating for display
*/ */
formatRating: (rating: number) => string; formatRating: (rating: number | undefined) => string;
} }
// Timeline event for author pages // Timeline event for author pages

View File

@ -33,7 +33,8 @@ export const authorUtils: AuthorDisplayUtils = {
/** /**
* Format numbers for display * Format numbers for display
*/ */
formatNumber: (num: number, format: 'numbers' | 'abbreviated' | 'full' = 'full'): string => { formatNumber: (num: number | undefined, format: 'numbers' | 'abbreviated' | 'full' = 'numbers'): string => {
if (num === undefined) return '';
if (format === 'abbreviated') { if (format === 'abbreviated') {
if (num >= 1000000) return `${(num / 1000000).toFixed(1)}M`; if (num >= 1000000) return `${(num / 1000000).toFixed(1)}M`;
if (num >= 1000) return `${(num / 1000).toFixed(1)}K`; if (num >= 1000) return `${(num / 1000).toFixed(1)}K`;
@ -48,7 +49,8 @@ export const authorUtils: AuthorDisplayUtils = {
/** /**
* Format rating for display * Format rating for display
*/ */
formatRating: (rating: number): string => { formatRating: (rating: number | undefined): string => {
if (rating === undefined) return '';
return rating.toFixed(1); return rating.toFixed(1);
}, },

View File

@ -1,12 +1,3 @@
import {
Edit,
MessageCircle,
MessageSquare,
ThumbsUp,
Trash,
X,
} from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { import {
@ -19,6 +10,15 @@ import {
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
import { useToast } from "@/hooks/use-toast"; import { useToast } from "@/hooks/use-toast";
import type { AnnotationWithUser } from "@shared/schema"; import type { AnnotationWithUser } from "@shared/schema";
import {
Edit,
MessageCircle,
MessageSquare,
ThumbsUp,
Trash,
X,
} from "lucide-react";
import { useEffect, useRef, useState } from "react";
interface AnnotationSystemProps { interface AnnotationSystemProps {
workId: string; workId: string;
@ -47,7 +47,7 @@ export function AnnotationSystem({
// Mock user data - in a real app this would come from auth // Mock user data - in a real app this would come from auth
const currentUser = { const currentUser = {
id: 1, id: "1",
name: "Anonymous", name: "Anonymous",
avatar: null, avatar: null,
}; };
@ -72,13 +72,13 @@ export function AnnotationSystem({
name: "Literary Scholar", name: "Literary Scholar",
avatar: undefined, avatar: undefined,
}, },
likes: 5,
liked: false,
content: content:
"This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.", "This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.",
type: "analysis", type: "analysis",
isOfficial: false, isOfficial: false,
createdAt: new Date(Date.now() - 1000000).toISOString(), createdAt: new Date(Date.now() - 1000000).toISOString(),
likes: 5,
liked: false,
}, },
{ {
id: "2", id: "2",
@ -90,13 +90,13 @@ export function AnnotationSystem({
name: "Translator", name: "Translator",
avatar: undefined, avatar: undefined,
}, },
likes: 3,
liked: false,
content: content:
"The original meaning in Russian contains a wordplay that is difficult to capture in English. A more literal translation might read as...", "The original meaning in Russian contains a wordplay that is difficult to capture in English. A more literal translation might read as...",
type: "translation", type: "translation",
isOfficial: false, isOfficial: false,
createdAt: new Date(Date.now() - 5000000).toISOString(), createdAt: new Date(Date.now() - 5000000).toISOString(),
likes: 3,
liked: false,
}, },
]; ];