refact: area text calculated by words

This commit is contained in:
Joshua Shoemaker 2023-06-27 08:22:33 -05:00
parent c499445569
commit 45e8ec2be3
3 changed files with 7 additions and 11 deletions

View File

@ -23,14 +23,12 @@ type ProcessedWord struct {
} }
type ProcessedLine struct { type ProcessedLine struct {
FullText string `json:"fullText"`
Words []ProcessedWord `json:"words"` Words []ProcessedWord `json:"words"`
} }
type ProcessedArea struct { type ProcessedArea struct {
Id string `json:"id"` Id string `json:"id"`
DocumentId string `json:"documentId"` DocumentId string `json:"documentId"`
FullText string `json:"fullText"`
Order int `json:"order"` Order int `json:"order"`
Lines []ProcessedLine `json:"lines"` Lines []ProcessedLine `json:"lines"`
} }

View File

@ -35,10 +35,10 @@ const AreaContextMenu = (props: Props) => {
const handleCopyButtonClick = async () => { const handleCopyButtonClick = async () => {
const processedArea = await getProcessedAreaById(area.id) const processedArea = await getProcessedAreaById(area.id)
console.log(processedArea) const wordsOfProcessedArea = processedArea?.lines.flatMap(l => l.words.map(w => w.fullText))
const fullText = processedArea?.fullText // TODO: change when `fullText` is calculated from processed words const fullText = wordsOfProcessedArea?.join(' ')
console.log('fullText: ', fullText)
if (!fullText) return // TODO: change to show notification when copy fails if (!fullText) return // TODO: change to show notification when copy fails
await navigator.clipboard.writeText(fullText) await navigator.clipboard.writeText(fullText)
setIsAreaContextMenuOpen(false) setIsAreaContextMenuOpen(false)
} }
@ -46,12 +46,14 @@ const AreaContextMenu = (props: Props) => {
const handleDeleteButtonClick = async () => { const handleDeleteButtonClick = async () => {
const response = await requestDeleteAreaById(area.id) const response = await requestDeleteAreaById(area.id)
if (!response) return // TODO: change to show notification when copy fails if (!response) return // TODO: change to show notification when copy fails
setIsAreaContextMenuOpen(false) setIsAreaContextMenuOpen(false)
} }
const handleReprocessButtonClick = async () => { const handleReprocessButtonClick = async () => {
const documentId = await getSelectedDocument()?.id const documentId = getSelectedDocument()?.id
if (!documentId) return // TODO: change to show notification when copy fails if (!documentId) return // TODO: change to show notification when copy fails
setIsAreaContextMenuOpen(false) // TODO: possibly have loading animation and wait until after process setIsAreaContextMenuOpen(false) // TODO: possibly have loading animation and wait until after process
await processImageArea(documentId, area.id) await processImageArea(documentId, area.id)
} }

View File

@ -278,7 +278,6 @@ export namespace entities {
} }
} }
export class ProcessedLine { export class ProcessedLine {
fullText: string;
words: ProcessedWord[]; words: ProcessedWord[];
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
@ -287,7 +286,6 @@ export namespace entities {
constructor(source: any = {}) { constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source); if ('string' === typeof source) source = JSON.parse(source);
this.fullText = source["fullText"];
this.words = this.convertValues(source["words"], ProcessedWord); this.words = this.convertValues(source["words"], ProcessedWord);
} }
@ -312,7 +310,6 @@ export namespace entities {
export class ProcessedArea { export class ProcessedArea {
id: string; id: string;
documentId: string; documentId: string;
fullText: string;
order: number; order: number;
lines: ProcessedLine[]; lines: ProcessedLine[];
@ -324,7 +321,6 @@ export namespace entities {
if ('string' === typeof source) source = JSON.parse(source); if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"]; this.id = source["id"];
this.documentId = source["documentId"]; this.documentId = source["documentId"];
this.fullText = source["fullText"];
this.order = source["order"]; this.order = source["order"];
this.lines = this.convertValues(source["lines"], ProcessedLine); this.lines = this.convertValues(source["lines"], ProcessedLine);
} }