refact: area text calculated by words
This commit is contained in:
		
							parent
							
								
									c499445569
								
							
						
					
					
						commit
						45e8ec2be3
					
				@ -23,14 +23,12 @@ type ProcessedWord struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ProcessedLine struct {
 | 
			
		||||
	FullText string          `json:"fullText"`
 | 
			
		||||
	Words    []ProcessedWord `json:"words"`
 | 
			
		||||
	Words []ProcessedWord `json:"words"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ProcessedArea struct {
 | 
			
		||||
	Id         string          `json:"id"`
 | 
			
		||||
	DocumentId string          `json:"documentId"`
 | 
			
		||||
	FullText   string          `json:"fullText"`
 | 
			
		||||
	Order      int             `json:"order"`
 | 
			
		||||
	Lines      []ProcessedLine `json:"lines"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -35,10 +35,10 @@ const AreaContextMenu = (props: Props) => {
 | 
			
		||||
 | 
			
		||||
  const handleCopyButtonClick = async () => {
 | 
			
		||||
    const processedArea = await getProcessedAreaById(area.id)
 | 
			
		||||
    console.log(processedArea)
 | 
			
		||||
    const fullText = processedArea?.fullText // TODO: change when `fullText` is calculated from processed words
 | 
			
		||||
    console.log('fullText: ', fullText)
 | 
			
		||||
    const wordsOfProcessedArea = processedArea?.lines.flatMap(l => l.words.map(w => w.fullText))
 | 
			
		||||
    const fullText = wordsOfProcessedArea?.join(' ')
 | 
			
		||||
    if (!fullText) return // TODO: change to show notification when copy fails
 | 
			
		||||
 | 
			
		||||
    await navigator.clipboard.writeText(fullText)
 | 
			
		||||
    setIsAreaContextMenuOpen(false)
 | 
			
		||||
  }
 | 
			
		||||
@ -46,12 +46,14 @@ const AreaContextMenu = (props: Props) => {
 | 
			
		||||
  const handleDeleteButtonClick = async () => {
 | 
			
		||||
    const response = await requestDeleteAreaById(area.id)
 | 
			
		||||
    if (!response) return // TODO: change to show notification when copy fails
 | 
			
		||||
 | 
			
		||||
    setIsAreaContextMenuOpen(false)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const handleReprocessButtonClick = async () => {
 | 
			
		||||
    const documentId = await getSelectedDocument()?.id
 | 
			
		||||
    const documentId = getSelectedDocument()?.id
 | 
			
		||||
    if (!documentId) return // TODO: change to show notification when copy fails
 | 
			
		||||
 | 
			
		||||
    setIsAreaContextMenuOpen(false) // TODO: possibly have loading animation and wait until after process
 | 
			
		||||
    await processImageArea(documentId, area.id)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -278,7 +278,6 @@ export namespace entities {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	export class ProcessedLine {
 | 
			
		||||
	    fullText: string;
 | 
			
		||||
	    words: ProcessedWord[];
 | 
			
		||||
	
 | 
			
		||||
	    static createFrom(source: any = {}) {
 | 
			
		||||
@ -287,7 +286,6 @@ export namespace entities {
 | 
			
		||||
	
 | 
			
		||||
	    constructor(source: any = {}) {
 | 
			
		||||
	        if ('string' === typeof source) source = JSON.parse(source);
 | 
			
		||||
	        this.fullText = source["fullText"];
 | 
			
		||||
	        this.words = this.convertValues(source["words"], ProcessedWord);
 | 
			
		||||
	    }
 | 
			
		||||
	
 | 
			
		||||
@ -312,7 +310,6 @@ export namespace entities {
 | 
			
		||||
	export class ProcessedArea {
 | 
			
		||||
	    id: string;
 | 
			
		||||
	    documentId: string;
 | 
			
		||||
	    fullText: string;
 | 
			
		||||
	    order: number;
 | 
			
		||||
	    lines: ProcessedLine[];
 | 
			
		||||
	
 | 
			
		||||
@ -324,7 +321,6 @@ export namespace entities {
 | 
			
		||||
	        if ('string' === typeof source) source = JSON.parse(source);
 | 
			
		||||
	        this.id = source["id"];
 | 
			
		||||
	        this.documentId = source["documentId"];
 | 
			
		||||
	        this.fullText = source["fullText"];
 | 
			
		||||
	        this.order = source["order"];
 | 
			
		||||
	        this.lines = this.convertValues(source["lines"], ProcessedLine);
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user