diff options
| author | bobzel <zzzman@gmail.com> | 2024-05-15 10:55:17 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2024-05-15 10:55:17 -0400 |
| commit | 213e5c5ab7dcb7a92a2d6c0e2ca10433ddc3141f (patch) | |
| tree | 01a4c5501ce4e6ce8fb74c4a64acb6bc77c5562e /src/client/views/newlightbox/RecommendationList | |
| parent | c329d7719ed60d71bec4a8ac7309e33081c3373c (diff) | |
| parent | 0b1d434ad7f0d057456631ac786ed338c84a7f41 (diff) | |
merged with new eslint code
Diffstat (limited to 'src/client/views/newlightbox/RecommendationList')
3 files changed, 71 insertions, 76 deletions
diff --git a/src/client/views/newlightbox/RecommendationList/RecommendationList.tsx b/src/client/views/newlightbox/RecommendationList/RecommendationList.tsx index 1d502b73f..dc3339cd3 100644 --- a/src/client/views/newlightbox/RecommendationList/RecommendationList.tsx +++ b/src/client/views/newlightbox/RecommendationList/RecommendationList.tsx @@ -1,3 +1,7 @@ +/* eslint-disable react/jsx-props-no-spreading */ +/* eslint-disable jsx-a11y/no-static-element-interactions */ +/* eslint-disable jsx-a11y/click-events-have-key-events */ +/* eslint-disable guard-for-in */ import { IconButton, Size, Type } from 'browndash-components'; import * as React from 'react'; import { FaCaretDown, FaCaretUp } from 'react-icons/fa'; @@ -5,17 +9,15 @@ import { GrClose } from 'react-icons/gr'; import { DocListCast, StrListCast } from '../../../../fields/Doc'; import { List } from '../../../../fields/List'; import { StrCast } from '../../../../fields/Types'; -import { LightboxView } from '../../LightboxView'; import { Colors } from '../../global/globalEnums'; +import { DocumentView } from '../../nodes/DocumentView'; import { IBounds } from '../ExploreView/utils'; import { NewLightboxView } from '../NewLightboxView'; import { IRecommendation, Recommendation } from '../components'; import { IDocRequest, fetchKeywords, fetchRecommendations } from '../utils'; import './RecommendationList.scss'; -import { IRecommendationList } from './utils'; -export const RecommendationList = (props: IRecommendationList) => { - const { loading, keywords } = props; +export function RecommendationList() { const [loadingKeywords, setLoadingKeywords] = React.useState<boolean>(true); const [showMore, setShowMore] = React.useState<boolean>(false); const [keywordsLoc, setKeywordsLoc] = React.useState<string[]>([]); @@ -25,21 +27,22 @@ export const RecommendationList = (props: IRecommendationList) => { React.useEffect(() => { const getKeywords = async () => { - let text = StrCast(LightboxView.LightboxDoc?.text); + const text = StrCast(DocumentView.LightboxDoc()?.text); console.log('[1] fetching keywords'); const response = await fetchKeywords(text, 5, true); console.log('[2] response:', response); const kw = response.keywords; console.log(kw); NewLightboxView.SetKeywords(kw); - if (LightboxView.LightboxDoc) { + const lightboxDoc = DocumentView.LightboxDoc(); + if (lightboxDoc) { console.log('setting keywords on doc'); - LightboxView.LightboxDoc.keywords = new List<string>(kw); + lightboxDoc.keywords = new List<string>(kw); setKeywordsLoc(NewLightboxView.Keywords); } setLoadingKeywords(false); }; - let keywordsList = StrListCast(LightboxView.LightboxDoc!.keywords); + const keywordsList = StrListCast(DocumentView.LightboxDoc()!.keywords); if (!keywordsList || keywordsList.length < 2) { setLoadingKeywords(true); getKeywords(); @@ -57,14 +60,14 @@ export const RecommendationList = (props: IRecommendationList) => { console.log('fetching recommendations'); let query = 'undefined'; if (keywordsLoc) query = keywordsLoc.join(','); - let src = StrCast(NewLightboxView.LightboxDoc?.text); - let dashDocs: IDocRequest[] = []; + const src = StrCast(NewLightboxView.LightboxDoc?.text); + const dashDocs: IDocRequest[] = []; // get linked docs - let linkedDocs = DocListCast(NewLightboxView.LightboxDoc?.links); + const linkedDocs = DocListCast(NewLightboxView.LightboxDoc?.links); console.log('linked docs', linkedDocs); // get context docs (docs that are also in the collection) - // let contextDocs: Doc[] = DocListCast(DocCast(LightboxView.LightboxDoc?.context).data) - // let docId = LightboxView.LightboxDoc && LightboxView.LightboxDoc[Id] + // let contextDocs: Doc[] = DocListCast(DocCast(DocumentView.LightboxDoc()?.context).data) + // let docId = DocumentView.LightboxDoc() && DocumentView.LightboxDoc()[Id] // console.log("context docs", contextDocs) // contextDocs.forEach((doc: Doc) => { // if (docId !== doc[Id]){ @@ -79,10 +82,8 @@ export const RecommendationList = (props: IRecommendationList) => { console.log('dash docs', dashDocs); if (query !== undefined) { const response = await fetchRecommendations(src, query, [], true); - const num_recs = response.num_recommendations; - const recs = response.recommendations; - const keywords = response.keywords; - const response_bounds: IBounds = { + const theRecs = response.recommendations; + const responseBounds: IBounds = { max_x: response.max_x, max_y: response.max_y, min_x: response.min_x, @@ -93,22 +94,23 @@ export const RecommendationList = (props: IRecommendationList) => { // setKeywordsLoc(NewLightboxView.Keywords); // } // console.log(response_bounds) - NewLightboxView.SetBounds(response_bounds); + NewLightboxView.SetBounds(responseBounds); const recommendations: IRecommendation[] = []; - for (const key in recs) { + // eslint-disable-next-line no-restricted-syntax + for (const key in theRecs) { console.log(key); - const title = recs[key].title; - const url = recs[key].url; - const type = recs[key].type; - const text = recs[key].text; - const transcript = recs[key].transcript; - const previewUrl = recs[key].previewUrl; - const embedding = recs[key].embedding; - const distance = recs[key].distance; - const source = recs[key].source; - const related_concepts = recs[key].related_concepts; - const docId = recs[key].doc_id; - related_concepts.length >= 1 && + const { title } = theRecs[key]; + const { url } = theRecs[key]; + const { type } = theRecs[key]; + const { text } = theRecs[key]; + const { transcript } = theRecs[key]; + const { previewUrl } = theRecs[key]; + const { embedding } = theRecs[key]; + const { distance } = theRecs[key]; + const { source } = theRecs[key]; + const { related_concepts: relatedConcepts } = theRecs[key]; + const docId = theRecs[key].doc_id; + relatedConcepts.length >= 1 && recommendations.push({ title: title, data: url, @@ -119,14 +121,15 @@ export const RecommendationList = (props: IRecommendationList) => { embedding: embedding, distance: Math.round(distance * 100) / 100, source: source, - related_concepts: related_concepts, + related_concepts: relatedConcepts, docId: docId, }); } recommendations.sort((a, b) => { if (a.distance && b.distance) { return a.distance - b.distance; - } else return 0; + } + return 0; }); console.log('[rec]: ', recommendations); NewLightboxView.SetRecs(recommendations); @@ -138,12 +141,12 @@ export const RecommendationList = (props: IRecommendationList) => { return ( <div - className={`recommendationlist-container`} + className="recommendationlist-container" onPointerDown={e => { e.stopPropagation(); }}> - <div className={`header`}> - <div className={`title`}>Recommendations</div> + <div className="header"> + <div className="title">Recommendations</div> {NewLightboxView.LightboxDoc && ( <div style={{ fontSize: 10 }}> The recommendations are produced based on the text in the document{' '} @@ -153,65 +156,58 @@ export const RecommendationList = (props: IRecommendationList) => { . The following keywords are used to fetch the recommendations. </div> )} - <div className={`lb-label`}>Keywords</div> + <div className="lb-label">Keywords</div> {loadingKeywords ? ( - <div className={`keywords`}> + <div className="keywords"> <div className={`keyword ${loadingKeywords && 'loading'}`} /> <div className={`keyword ${loadingKeywords && 'loading'}`} /> <div className={`keyword ${loadingKeywords && 'loading'}`} /> <div className={`keyword ${loadingKeywords && 'loading'}`} /> </div> ) : ( - <div className={`keywords`}> + <div className="keywords"> {keywordsLoc && - keywordsLoc.map((word, ind) => { - return ( - <div className={`keyword`}> - {word} - <IconButton - type={Type.PRIM} - size={Size.XSMALL} - color={Colors.DARK_GRAY} - icon={<GrClose />} - onClick={() => { - let kw = keywordsLoc; - kw.splice(ind); - NewLightboxView.SetKeywords(kw); - }} - /> - </div> - ); - })} + keywordsLoc.map((word, ind) => ( + <div className="keyword"> + {word} + <IconButton + type={Type.PRIM} + size={Size.XSMALL} + color={Colors.DARK_GRAY} + icon={<GrClose />} + onClick={() => { + const kw = keywordsLoc; + kw.splice(ind); + NewLightboxView.SetKeywords(kw); + }} + /> + </div> + ))} </div> )} {!showMore ? ( <div - className={`lb-caret`} + className="lb-caret" onClick={() => { setShowMore(true); }}> More <FaCaretDown /> </div> ) : ( - <div className={`more`}> + <div className="more"> <div - className={`lb-caret`} + className="lb-caret" onClick={() => { setShowMore(false); }}> Less <FaCaretUp /> </div> - <div className={`lb-label`}>Type</div> - <div className={`lb-label`}>Sources</div> + <div className="lb-label">Type</div> + <div className="lb-label">Sources</div> </div> )} </div> - <div className={`recommendations`}> - {recs && - recs.map((rec: IRecommendation) => { - return <Recommendation {...rec} />; - })} - </div> + <div className="recommendations">{recs && recs.map((rec: IRecommendation) => <Recommendation {...rec} />)}</div> </div> ); -}; +} diff --git a/src/client/views/newlightbox/RecommendationList/index.ts b/src/client/views/newlightbox/RecommendationList/index.ts index f4555c1f2..226eafb7e 100644 --- a/src/client/views/newlightbox/RecommendationList/index.ts +++ b/src/client/views/newlightbox/RecommendationList/index.ts @@ -1 +1 @@ -export * from './RecommendationList'
\ No newline at end of file +export * from './RecommendationList'; diff --git a/src/client/views/newlightbox/RecommendationList/utils.ts b/src/client/views/newlightbox/RecommendationList/utils.ts index cdfff3258..fbf8ac19f 100644 --- a/src/client/views/newlightbox/RecommendationList/utils.ts +++ b/src/client/views/newlightbox/RecommendationList/utils.ts @@ -1,9 +1,8 @@ -import { IRecommendation } from "../components"; +import { IRecommendation } from '../components'; export interface IRecommendationList { - loading?: boolean, - keywords?: string[], - recs?: IRecommendation[] - getRecs?: any + loading?: boolean; + keywords?: string[]; + recs?: IRecommendation[]; + getRecs?: any; } - |
