@@ -23,10 +23,12 @@ const verificationConfig = {
2323} ;
2424
2525function FactoidCard ( { factoid, onSave } : { factoid : Factoid , onSave ?: FactoidsResultsProps [ 'onSaveSource' ] } ) {
26- const config = verificationConfig [ factoid . citation . verified ] ;
26+ // Defensive check for old data format in localStorage
27+ const verified = factoid . citation ?. verified ?? 'pending' ;
28+ const config = verificationConfig [ verified ] ?? verificationConfig . pending ;
2729 const VerifyIcon = config . icon ;
2830 // Use secure URL validation instead of simple string checks
29- const safeUrl = validateUrl ( factoid . citation . url ) ;
31+ const safeUrl = validateUrl ( factoid . citation ? .url ) ;
3032
3133 return (
3234 < div className = "rounded-lg border border-border bg-card p-4 space-y-4" >
@@ -65,7 +67,7 @@ function FactoidCard({ factoid, onSave }: { factoid: Factoid, onSave?: FactoidsR
6567 variant = "ghost"
6668 size = "icon"
6769 className = "h-8 w-8 text-muted-foreground hover:text-primary"
68- onClick = { ( ) => onSave ( factoid . shortClaim , `${ factoid . context } \n\nKey Figure: ${ factoid . keyFigure } \nLimitations: ${ factoid . limitations } ` , factoid . citation . url ) }
70+ onClick = { ( ) => onSave ( factoid . shortClaim , `${ factoid . context } \n\nKey Figure: ${ factoid . keyFigure } \nLimitations: ${ factoid . limitations } ` , factoid . citation ? .url ) }
6971 title = "Save to Library"
7072 >
7173 < Bookmark className = "h-4 w-4" />
@@ -94,10 +96,10 @@ function FactoidCard({ factoid, onSave }: { factoid: Factoid, onSave?: FactoidsR
9496
9597 { /* Citation Block */ }
9698 < div className = "rounded-md bg-muted/50 p-3 space-y-1 text-sm text-left" >
97- < div className = "font-medium text-foreground" > { factoid . citation . title } </ div >
99+ < div className = "font-medium text-foreground" > { factoid . citation ? .title || 'Unknown Source' } </ div >
98100 < div className = "text-muted-foreground" >
99- { factoid . citation . publisher }
100- { factoid . citation . date && ` • ${ factoid . citation . date } ` }
101+ { factoid . citation ? .publisher || 'Unknown' }
102+ { factoid . citation ? .date && ` • ${ factoid . citation . date } ` }
101103 </ div >
102104 { safeUrl ? (
103105 < a
@@ -126,8 +128,8 @@ function FactoidCard({ factoid, onSave }: { factoid: Factoid, onSave?: FactoidsR
126128}
127129
128130export function FactoidsResults ( { result, onVerify, isVerifying, onDiscuss, onSaveSource } : FactoidsResultsProps ) {
129- const verifiedCount = result . factoids . filter ( f => f . citation . verified === 'verified' ) . length ;
130- const unverifiedCount = result . factoids . filter ( f => f . citation . verified === 'unverified' ) . length ;
131+ const verifiedCount = result . factoids . filter ( f => f . citation ? .verified === 'verified' ) . length ;
132+ const unverifiedCount = result . factoids . filter ( f => f . citation ? .verified === 'unverified' ) . length ;
131133
132134 return (
133135 < div className = "space-y-6" >
0 commit comments