mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 04:51:34 +00:00
fix: resolve major TypeScript errors and type mismatches
- Add AuthorWithStats and AnnotationWithUser schemas with proper relations - Fix AnnotationSystem component type issues (string IDs, nested user objects) - Update component props to match schema expectations - Fix function parameter types for annotation operations - Resolve null/undefined type assignments - Add missing required properties (type, isOfficial) to annotations Remaining issues: Test ES module configuration and some component prop type mismatches
This commit is contained in:
parent
8e6df7d0cc
commit
470a0faa1b
@ -18,13 +18,13 @@ import {
|
|||||||
} from "@/components/ui/card";
|
} from "@/components/ui/card";
|
||||||
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 "@/lib/types";
|
import type { AnnotationWithUser } from "@shared/schema";
|
||||||
|
|
||||||
interface AnnotationSystemProps {
|
interface AnnotationSystemProps {
|
||||||
workId: number;
|
workId: string;
|
||||||
selectedLineNumber: number | null;
|
selectedLineNumber: number | null;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
translationId?: number;
|
translationId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AnnotationSystem({
|
export function AnnotationSystem({
|
||||||
@ -38,7 +38,7 @@ export function AnnotationSystem({
|
|||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [newAnnotation, setNewAnnotation] = useState("");
|
const [newAnnotation, setNewAnnotation] = useState("");
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [editingAnnotationId, setEditingAnnotationId] = useState<number | null>(
|
const [editingAnnotationId, setEditingAnnotationId] = useState<string | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const [editText, setEditText] = useState("");
|
const [editText, setEditText] = useState("");
|
||||||
@ -63,32 +63,40 @@ export function AnnotationSystem({
|
|||||||
// These would be fetched from the API in a real app
|
// These would be fetched from the API in a real app
|
||||||
const mockAnnotations: AnnotationWithUser[] = [
|
const mockAnnotations: AnnotationWithUser[] = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: "1",
|
||||||
workId,
|
workId: workId,
|
||||||
translationId,
|
translationId: translationId,
|
||||||
lineNumber: selectedLineNumber,
|
lineNumber: selectedLineNumber,
|
||||||
userId: 2,
|
userId: "2",
|
||||||
userName: "Literary Scholar",
|
user: {
|
||||||
userAvatar: null,
|
name: "Literary Scholar",
|
||||||
content:
|
avatar: undefined,
|
||||||
"This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.",
|
},
|
||||||
createdAt: new Date(Date.now() - 1000000).toISOString(),
|
|
||||||
likes: 5,
|
likes: 5,
|
||||||
liked: false,
|
liked: false,
|
||||||
|
content:
|
||||||
|
"This line demonstrates the poet's use of alliteration, creating a rhythmic pattern that emphasizes the emotional tone.",
|
||||||
|
type: "analysis",
|
||||||
|
isOfficial: false,
|
||||||
|
createdAt: new Date(Date.now() - 1000000).toISOString(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: "2",
|
||||||
workId,
|
workId: workId,
|
||||||
translationId,
|
translationId: translationId,
|
||||||
lineNumber: selectedLineNumber,
|
lineNumber: selectedLineNumber,
|
||||||
userId: 3,
|
userId: "3",
|
||||||
userName: "Translator",
|
user: {
|
||||||
userAvatar: null,
|
name: "Translator",
|
||||||
|
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",
|
||||||
|
isOfficial: false,
|
||||||
createdAt: new Date(Date.now() - 5000000).toISOString(),
|
createdAt: new Date(Date.now() - 5000000).toISOString(),
|
||||||
likes: 12,
|
|
||||||
liked: true,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -107,14 +115,18 @@ export function AnnotationSystem({
|
|||||||
// In a real app, this would be an API call
|
// In a real app, this would be an API call
|
||||||
// Mock API response
|
// Mock API response
|
||||||
const newAnnotationObj: AnnotationWithUser = {
|
const newAnnotationObj: AnnotationWithUser = {
|
||||||
id: Date.now(),
|
id: Date.now().toString(),
|
||||||
workId,
|
workId,
|
||||||
translationId,
|
translationId,
|
||||||
lineNumber: selectedLineNumber,
|
lineNumber: selectedLineNumber,
|
||||||
userId: currentUser.id,
|
userId: currentUser.id.toString(),
|
||||||
userName: currentUser.name,
|
user: {
|
||||||
userAvatar: currentUser.avatar,
|
name: currentUser.name,
|
||||||
|
avatar: currentUser.avatar || undefined,
|
||||||
|
},
|
||||||
content: newAnnotation,
|
content: newAnnotation,
|
||||||
|
type: "comment",
|
||||||
|
isOfficial: false,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
likes: 0,
|
likes: 0,
|
||||||
liked: false,
|
liked: false,
|
||||||
@ -142,7 +154,7 @@ export function AnnotationSystem({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Like an annotation
|
// Like an annotation
|
||||||
const handleLikeAnnotation = async (annotationId: number) => {
|
const handleLikeAnnotation = async (annotationId: string) => {
|
||||||
try {
|
try {
|
||||||
// Optimistically update UI
|
// Optimistically update UI
|
||||||
setAnnotations((prev) =>
|
setAnnotations((prev) =>
|
||||||
@ -151,7 +163,7 @@ export function AnnotationSystem({
|
|||||||
? {
|
? {
|
||||||
...anno,
|
...anno,
|
||||||
liked: !anno.liked,
|
liked: !anno.liked,
|
||||||
likes: anno.liked ? anno.likes - 1 : anno.likes + 1,
|
likes: anno.liked ? (anno.likes || 0) - 1 : (anno.likes || 0) + 1,
|
||||||
}
|
}
|
||||||
: anno,
|
: anno,
|
||||||
),
|
),
|
||||||
@ -171,7 +183,7 @@ export function AnnotationSystem({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Delete annotation
|
// Delete annotation
|
||||||
const handleDeleteAnnotation = async (annotationId: number) => {
|
const handleDeleteAnnotation = async (annotationId: string) => {
|
||||||
try {
|
try {
|
||||||
// Optimistically update UI
|
// Optimistically update UI
|
||||||
const filteredAnnotations = annotations.filter(
|
const filteredAnnotations = annotations.filter(
|
||||||
@ -202,7 +214,7 @@ export function AnnotationSystem({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Save edited annotation
|
// Save edited annotation
|
||||||
const handleSaveEdit = async (annotationId: number) => {
|
const handleSaveEdit = async (annotationId: string) => {
|
||||||
if (!editText.trim()) return;
|
if (!editText.trim()) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -309,16 +321,16 @@ export function AnnotationSystem({
|
|||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Avatar className="h-8 w-8">
|
<Avatar className="h-8 w-8">
|
||||||
<AvatarImage
|
<AvatarImage
|
||||||
src={annotation.userAvatar || ""}
|
src={annotation.user.avatar || ""}
|
||||||
alt={annotation.userName}
|
alt={annotation.user.name}
|
||||||
/>
|
/>
|
||||||
<AvatarFallback className="text-xs bg-navy/10 dark:bg-navy/20 text-navy dark:text-cream">
|
<AvatarFallback className="text-xs bg-navy/10 dark:bg-navy/20 text-navy dark:text-cream">
|
||||||
{annotation.userName.charAt(0).toUpperCase()}
|
{annotation.user.name.charAt(0).toUpperCase()}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div>
|
<div>
|
||||||
<CardTitle className="text-sm font-medium text-navy dark:text-cream">
|
<CardTitle className="text-sm font-medium text-navy dark:text-cream">
|
||||||
{annotation.userName}
|
{annotation.user.name}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<p className="text-xs text-navy/60 dark:text-cream/60">
|
<p className="text-xs text-navy/60 dark:text-cream/60">
|
||||||
{new Date(annotation.createdAt).toLocaleDateString()}
|
{new Date(annotation.createdAt).toLocaleDateString()}
|
||||||
@ -327,7 +339,7 @@ export function AnnotationSystem({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Edit/Delete buttons for user's own annotations */}
|
{/* Edit/Delete buttons for user's own annotations */}
|
||||||
{annotation.userId === currentUser.id && (
|
{annotation.userId === currentUser.id.toString() && (
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user