@@ -933,9 +933,11 @@ export function CollectionsPicker({ item, onUpdate, updateFn }) {
933933 )
934934}
935935
936- export default function PaperInfoPanel ( { paper, onStatusChange, onPaperUpdate } ) {
936+ export default function PaperInfoPanel ( { paper, onStatusChange, onPaperUpdate, allTags = [ ] } ) {
937937 const [ paperAuthorLinks , setPaperAuthorLinks ] = useState ( [ ] )
938-
938+ const [ tagInput , setTagInput ] = useState ( '' )
939+ const [ showTagSuggestions , setShowTagSuggestions ] = useState ( false )
940+ const tagContainerRef = useRef ( null )
939941 useEffect ( ( ) => {
940942 if ( paper ?. id ) loadAuthorLinks ( )
941943 function onLinksChanged ( ) { loadAuthorLinks ( ) }
@@ -950,6 +952,39 @@ export default function PaperInfoPanel({ paper, onStatusChange, onPaperUpdate })
950952 } catch ( _ ) { /* silently fail — links are optional enrichment */ }
951953 }
952954
955+ const tagSuggestions = allTags . filter ( t =>
956+ t . toLowerCase ( ) . includes ( tagInput . toLowerCase ( ) ) &&
957+ ! ( paper . tags || [ ] ) . includes ( t )
958+ )
959+
960+ async function saveTags ( newTags ) {
961+ try {
962+ const updated = await papersApi . update ( paper . id , { tags : newTags } )
963+ onPaperUpdate ?. ( updated )
964+ } catch ( err ) {
965+ console . error ( 'Failed to update tags:' , err )
966+ }
967+ }
968+
969+ function addTag ( tag ) {
970+ const trimmed = tag . trim ( )
971+ if ( ! trimmed || ( paper . tags || [ ] ) . includes ( trimmed ) ) return
972+ saveTags ( [ ...( paper . tags || [ ] ) , trimmed ] )
973+ setTagInput ( '' )
974+ setShowTagSuggestions ( false )
975+ }
976+
977+ useEffect ( ( ) => {
978+ if ( ! showTagSuggestions ) return
979+ const handleClickOutside = ( e ) => {
980+ if ( tagContainerRef . current && ! tagContainerRef . current . contains ( e . target ) ) {
981+ setShowTagSuggestions ( false )
982+ }
983+ }
984+ document . addEventListener ( 'mousedown' , handleClickOutside )
985+ return ( ) => document . removeEventListener ( 'mousedown' , handleClickOutside )
986+ } , [ showTagSuggestions ] )
987+
953988 async function handleStatusChange ( newStatus ) {
954989 try {
955990 await papersApi . update ( paper . id , { status : newStatus } )
@@ -1062,23 +1097,55 @@ export default function PaperInfoPanel({ paper, onStatusChange, onPaperUpdate })
10621097 < CitationPanel paper = { paper } />
10631098
10641099 { /* Tags */ }
1065- { paper . tags ?. length > 0 && (
1066- < div >
1067- < p className = "text-[10px] font-semibold text-slate-400 uppercase tracking-widest mb-2" > Tags</ p >
1068- < div className = "flex flex-wrap gap-1.5" >
1069- { paper . tags . map ( tag => (
1070- < span
1071- key = { tag }
1072- className = { `text-[11px] px-2 py-0.5 rounded-full ${
1073- paper . source === 'agent' ? 'bg-purple-100 text-purple-700' : 'bg-slate-100 text-slate-600'
1074- } `}
1100+ < div >
1101+ < p className = "text-[10px] font-semibold text-slate-400 uppercase tracking-widest mb-2" > Tags</ p >
1102+ < div className = "flex flex-wrap gap-1.5 items-center" >
1103+ { ( paper . tags || [ ] ) . map ( tag => (
1104+ < span
1105+ key = { tag }
1106+ className = { `group flex items-center gap-0.5 text-[11px] pl-2 pr-1 py-0.5 rounded-full ${
1107+ paper . source === 'agent' ? 'bg-purple-100 text-purple-700' : 'bg-slate-100 text-slate-600'
1108+ } `}
1109+ >
1110+ { tag }
1111+ < button
1112+ onClick = { ( ) => saveTags ( ( paper . tags || [ ] ) . filter ( t => t !== tag ) ) }
1113+ className = "text-slate-400 hover:text-red-500 transition-colors leading-none"
1114+ title = "Remove tag"
10751115 >
1076- { tag }
1077- </ span >
1078- ) ) }
1116+ < Icon name = "close" className = "text-[10px]" />
1117+ </ button >
1118+ </ span >
1119+ ) ) }
1120+ { /* Inline add input */ }
1121+ < div className = "relative" ref = { tagContainerRef } >
1122+ < input
1123+ value = { tagInput }
1124+ onChange = { e => { setTagInput ( e . target . value ) ; setShowTagSuggestions ( true ) } }
1125+ onKeyDown = { e => {
1126+ if ( e . key === 'Enter' && tagInput . trim ( ) ) { e . preventDefault ( ) ; addTag ( tagInput . trim ( ) ) }
1127+ else if ( e . key === 'Escape' ) { setShowTagSuggestions ( false ) ; setTagInput ( '' ) }
1128+ } }
1129+ onFocus = { ( ) => setShowTagSuggestions ( true ) }
1130+ placeholder = "Add tag…"
1131+ className = "text-[11px] px-2 py-0.5 rounded-full border border-dashed border-slate-300 bg-transparent text-slate-500 placeholder-slate-300 focus:outline-none focus:border-blue-400 w-20 focus:w-28 transition-all"
1132+ />
1133+ { showTagSuggestions && tagSuggestions . length > 0 && (
1134+ < div className = "absolute left-0 top-full mt-1 z-20 bg-white border border-slate-200 rounded-lg shadow-lg py-1 max-h-36 overflow-y-auto min-w-[120px]" >
1135+ { tagSuggestions . map ( s => (
1136+ < button
1137+ key = { s }
1138+ onMouseDown = { e => { e . preventDefault ( ) ; addTag ( s ) } }
1139+ className = "flex items-center w-full px-3 py-1 text-xs text-slate-700 hover:bg-slate-50 transition-colors"
1140+ >
1141+ { s }
1142+ </ button >
1143+ ) ) }
1144+ </ div >
1145+ ) }
10791146 </ div >
10801147 </ div >
1081- ) }
1148+ </ div >
10821149
10831150 { /* Agent provenance */ }
10841151 { paper . source === 'agent' && paper . agentRun && (
0 commit comments