fix: side bar line item arangement
This commit is contained in:
parent
93013675aa
commit
d69f02f2c4
@ -24,11 +24,12 @@ const AreaLineItem = (props: { area: SidebarArea, documentId: string, index: num
|
||||
selectedAreaId,
|
||||
isEditAreaNameInputShowing,
|
||||
setIsEditAreaNameInputShowing,
|
||||
dragOverAreaId,
|
||||
setDragOverAreaId,
|
||||
} = useSidebar()
|
||||
|
||||
const editAreaNameTextInput = useRef<HTMLInputElement>(null)
|
||||
|
||||
const [dragOverAreaId, setDragOverAreaId] = useState('')
|
||||
|
||||
const onConfirmAreaNameChangeHandler = async (areaDetails: { areaId: string, areaName: string }) => {
|
||||
const { areaId, areaName } = areaDetails
|
||||
@ -66,6 +67,8 @@ const AreaLineItem = (props: { area: SidebarArea, documentId: string, index: num
|
||||
}
|
||||
|
||||
const onAreaDropEnd = (areaId: string) => {
|
||||
if (!areaId || areaId == dragOverAreaId) return
|
||||
|
||||
const areaDroppedOn = getAreaById(dragOverAreaId)
|
||||
console.log(areaDroppedOn)
|
||||
if (!areaDroppedOn) return
|
||||
|
||||
@ -12,7 +12,7 @@ import { SidebarGroup } from './types'
|
||||
|
||||
|
||||
|
||||
const GroupLineItem = (props: { group: SidebarGroup }) => {
|
||||
const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => {
|
||||
const {
|
||||
requestAddDocument,
|
||||
requestChangeGroupOrder,
|
||||
@ -26,12 +26,12 @@ const GroupLineItem = (props: { group: SidebarGroup }) => {
|
||||
setSelectedGroupId,
|
||||
setIsAddNewDocumentInputShowing,
|
||||
setIsAddNewGroupInputShowing,
|
||||
dragOverGroupId,
|
||||
setDragOverGroupId
|
||||
} = useSidebar()
|
||||
|
||||
const addDocumentTextInput = useRef<HTMLInputElement>(null)
|
||||
|
||||
const [dragOverGroupId, setDragOverGroupId] = useState('')
|
||||
|
||||
const onConfirmAddDocumentClickHandler = async (groupId: string) => {
|
||||
const documentName = addDocumentTextInput.current?.value
|
||||
if (!documentName) return
|
||||
@ -63,10 +63,12 @@ const GroupLineItem = (props: { group: SidebarGroup }) => {
|
||||
}
|
||||
|
||||
const onGroupDropEnd = (groupId: string) => {
|
||||
const areaDroppedOn = getGroupById(groupId)
|
||||
console.log('areaDroppedOn', areaDroppedOn)
|
||||
if (!areaDroppedOn) return
|
||||
const response = requestChangeGroupOrder(groupId, areaDroppedOn.order)
|
||||
if (!groupId || groupId == dragOverGroupId) return
|
||||
|
||||
const groupDroppedOn = getGroupById(dragOverGroupId)
|
||||
console.log('groupDroppedOn', groupDroppedOn)
|
||||
if (!groupDroppedOn) return
|
||||
requestChangeGroupOrder(groupId, groupDroppedOn.order)
|
||||
setDragOverGroupId('')
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import React from 'react'
|
||||
import React, { useState } from 'react'
|
||||
import { useProject } from '../../../context/Project/provider'
|
||||
import AddGroupInput from './AddGroupInput'
|
||||
import GroupLineItem from './GroupLineItem'
|
||||
|
||||
@ -19,6 +19,9 @@ export function SidebarProvider({ children }: Props) {
|
||||
const [isEditDocumentNameInputShowing, setIsEditDocumentNameInputShowing] = useState(false)
|
||||
const [isAddNewGroupInputShowing, setIsAddNewGroupInputShowing] = useState(false)
|
||||
const [isEditAreaNameInputShowing, setIsEditAreaNameInputShowing] = useState(false)
|
||||
const [dragOverGroupId, setDragOverGroupId] = useState('')
|
||||
const [dragOverAreaId, setDragOverAreaId] = useState('')
|
||||
|
||||
|
||||
const {
|
||||
selectedDocumentId, setSelectedDocumentId,
|
||||
@ -44,7 +47,11 @@ export function SidebarProvider({ children }: Props) {
|
||||
isAddNewGroupInputShowing,
|
||||
setIsAddNewGroupInputShowing,
|
||||
isEditAreaNameInputShowing,
|
||||
setIsEditAreaNameInputShowing
|
||||
setIsEditAreaNameInputShowing,
|
||||
dragOverGroupId,
|
||||
setDragOverGroupId,
|
||||
dragOverAreaId,
|
||||
setDragOverAreaId,
|
||||
}
|
||||
|
||||
return <SidebarContext.Provider value={value}>
|
||||
|
||||
@ -14,6 +14,10 @@ export type SidebarContextType = {
|
||||
setIsAddNewGroupInputShowing: (_: boolean) => void,
|
||||
isEditAreaNameInputShowing: boolean,
|
||||
setIsEditAreaNameInputShowing: (_: boolean) => void,
|
||||
dragOverGroupId: string,
|
||||
setDragOverGroupId: (_: string) => void,
|
||||
dragOverAreaId: string,
|
||||
setDragOverAreaId: (_: string) => void,
|
||||
}
|
||||
|
||||
export type SidebarArea = {
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
||||
import makeDefaultProject from './makeDefaultProject'
|
||||
import { saveDocuments, saveGroups } from '../../useCases/saveData'
|
||||
|
||||
const ProjectContext = createContext<ProjectContextType>(makeDefaultProject())
|
||||
|
||||
@ -33,25 +34,11 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const [selectedDocumentId, setSelectedDocumentId] = useState<string>('')
|
||||
const [currentSession, setCurrentSession] = useState<ipc.Session>(new ipc.Session())
|
||||
|
||||
const saveDocumentsAndGroups = () => {
|
||||
RequestSaveDocumentCollection().then(success => {
|
||||
if (!success) console.error('Could not save DocumentCollection')
|
||||
}).catch(err => {
|
||||
console.error('Could not save DocumentCollection:', err)
|
||||
})
|
||||
RequestSaveGroupCollection().then(success => {
|
||||
if (!success) console.error('Could not save GroupCollection')
|
||||
}).catch(err => {
|
||||
console.error('Could not save GroupCollection:', err)
|
||||
})
|
||||
}
|
||||
|
||||
const updateDocuments = async () => {
|
||||
GetDocuments().then(response => {
|
||||
console.log(response)
|
||||
if (response.documents.length) setDocuments(response.documents)
|
||||
if (response.groups.length) setGroups(response.groups)
|
||||
saveDocumentsAndGroups()
|
||||
Promise.resolve(response)
|
||||
})
|
||||
}
|
||||
@ -59,18 +46,21 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const requestAddDocument = async (groupId: string, documentName: string) => {
|
||||
const response = await RequestAddDocument(groupId, documentName)
|
||||
if (response.id) await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
const requestAddDocumentGroup = async (groupName: string) => {
|
||||
const response = await RequestAddDocumentGroup(groupName)
|
||||
if (response.id) await updateDocuments()
|
||||
saveGroups()
|
||||
return response
|
||||
}
|
||||
|
||||
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<ipc.Area> => {
|
||||
const response = await RequestAddArea(documentId, new ipc.Area(area))
|
||||
if (response.id) await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
@ -78,6 +68,7 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const response = await RequestUpdateArea(new ipc.Area(updatedArea))
|
||||
|
||||
if (response.id) await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
@ -88,6 +79,7 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const requestDeleteAreaById = async (areaId: string): Promise<boolean> => {
|
||||
const wasSuccessfulDeletion = await RequestDeleteAreaById(areaId)
|
||||
if (wasSuccessfulDeletion) updateDocuments()
|
||||
saveDocuments()
|
||||
return wasSuccessfulDeletion
|
||||
}
|
||||
|
||||
@ -154,12 +146,14 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const requestUpdateDocument = async (docuemntProps: UpdateDocumentRequest) => {
|
||||
const response = await RequestUpdateDocument(new ipc.Document(docuemntProps))
|
||||
await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
const requestChangeAreaOrder = async (areaId: string, newOrder: number) => {
|
||||
const response = await RequestChangeAreaOrder(areaId, newOrder)
|
||||
await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
@ -169,7 +163,10 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
||||
|
||||
const requestChangeGroupOrder = async (groupId: string, newOrder: number) => {
|
||||
const response = await RequestChangeGroupOrder(groupId, newOrder)
|
||||
console.log('should be at ', newOrder)
|
||||
console.log(response)
|
||||
await updateDocuments()
|
||||
saveGroups()
|
||||
return response
|
||||
}
|
||||
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
import { createScheduler, createWorker } from 'tesseract.js'
|
||||
import { GetDocumentById } from '../wailsjs/wailsjs/go/ipc/Channel'
|
||||
import loadImage from './loadImage'
|
||||
|
||||
const getImageWorkerCount = (areaCount: number) => {
|
||||
const minWorkerCount = 1
|
||||
const maxWorkerCount = 10
|
||||
const areasPerWorker = 10
|
||||
|
||||
if (areaCount > maxWorkerCount * areasPerWorker) return maxWorkerCount;
|
||||
if (areaCount <= areasPerWorker) return minWorkerCount
|
||||
return ~~(areaCount / areasPerWorker)
|
||||
}
|
||||
|
||||
const processImageData = async (documentId: string) => {
|
||||
const foundDocument = await GetDocumentById(documentId)
|
||||
if (!foundDocument.path || !foundDocument.areas?.length) return
|
||||
|
||||
const { areas, path } = foundDocument
|
||||
const imageData = await loadImage(path)
|
||||
|
||||
const scheduler = createScheduler()
|
||||
const workerCount = getImageWorkerCount(areas.length)
|
||||
for (let index = 0; index < workerCount; index++) {
|
||||
const worker = await createWorker()
|
||||
await worker.loadLanguage('eng') // TODO: change this when multilangiage system is implementd
|
||||
await worker.initialize('eng') // TODO: same here
|
||||
scheduler.addWorker(worker)
|
||||
}
|
||||
|
||||
const results = await Promise.allSettled(areas.map(a => {
|
||||
return scheduler.addJob('recognize', imageData, { rectangle: {
|
||||
left: a.startX,
|
||||
top: a.startY,
|
||||
width: a.endX - a.startX,
|
||||
height: a.endY - a.startY,
|
||||
}})
|
||||
}))
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
export default processImageData
|
||||
24
frontend/useCases/saveData.ts
Normal file
24
frontend/useCases/saveData.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { RequestSaveDocumentCollection, RequestSaveGroupCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
||||
|
||||
const saveDocuments = async () => {
|
||||
try {
|
||||
const sucessfulSave = RequestSaveDocumentCollection()
|
||||
if (!sucessfulSave) console.error('Could not save DocumentCollection')
|
||||
} catch (err) {
|
||||
console.error('Could not save DocumentCollection:', err)
|
||||
}
|
||||
}
|
||||
|
||||
const saveGroups = async () => {
|
||||
try {
|
||||
const sucessfulSave = RequestSaveGroupCollection()
|
||||
if (!sucessfulSave) console.error('Could not save GroupCollection')
|
||||
} catch (err) {
|
||||
console.error('Could not save GroupCollection:', err)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
saveDocuments,
|
||||
saveGroups,
|
||||
}
|
||||
@ -388,10 +388,16 @@ func (c *Channel) RequestChangeAreaOrder(areaId string, newOrder int) Document {
|
||||
for index, a := range documentOfArea.Areas {
|
||||
if a.Id == areaId {
|
||||
documentOfArea.Areas[index].Order = newOrder
|
||||
processedAreasCollection.GetAreaById(a.Id).Order = newOrder
|
||||
foundProcessedArea := processedAreasCollection.GetAreaById(a.Id)
|
||||
if foundProcessedArea != nil {
|
||||
foundProcessedArea.Order = newOrder
|
||||
}
|
||||
} else if a.Order >= newOrder {
|
||||
documentOfArea.Areas[index].Order = a.Order + 1
|
||||
processedAreasCollection.GetAreaById(a.Id).Order = a.Order + 1
|
||||
foundProcessedArea := processedAreasCollection.GetAreaById(a.Id)
|
||||
if foundProcessedArea != nil {
|
||||
foundProcessedArea.Order = a.Order + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,9 +57,9 @@ func (c *Channel) CreateNewProject(name string) Session {
|
||||
}
|
||||
|
||||
successfulProjectWrite := storage.WriteLocalProjectData(storage.LocalProject{
|
||||
Id: uuid.NewString(),
|
||||
OrganizationId: currentSession.Project.OrganizationId,
|
||||
Name: name,
|
||||
Id: newProject.Id,
|
||||
OrganizationId: newProject.OrganizationId,
|
||||
Name: newProject.Name,
|
||||
})
|
||||
|
||||
if !successfulProjectWrite {
|
||||
|
||||
@ -30,7 +30,7 @@ func createLocalStorageDirIfNeeded() bool {
|
||||
}
|
||||
|
||||
errorCreatingDir := os.Mkdir(localStoragePath, os.ModePerm)
|
||||
return errorCreatingDir != nil
|
||||
return errorCreatingDir == nil
|
||||
}
|
||||
|
||||
func createLocalStorageSubDirIfNeeded(relativeSubdirectoryPath string) bool {
|
||||
@ -48,7 +48,7 @@ func createLocalStorageSubDirIfNeeded(relativeSubdirectoryPath string) bool {
|
||||
}
|
||||
|
||||
errorCreatingDir := os.MkdirAll(fullLocalStoragePath, os.ModePerm)
|
||||
return errorCreatingDir != nil
|
||||
return errorCreatingDir == nil
|
||||
}
|
||||
|
||||
func WriteLocalUserData(user LocalUser) bool {
|
||||
@ -110,13 +110,15 @@ func WriteLocalProjectData(project LocalProject) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Println(project)
|
||||
|
||||
subdirectory := "/projects/" + project.Name + "/"
|
||||
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
||||
if !isLocalStorageDirectoryCreated {
|
||||
return false
|
||||
}
|
||||
|
||||
err := os.WriteFile(GetLocalStoragePath()+subdirectory+project.Name+"/Project.json", file, 0644)
|
||||
err := os.WriteFile(GetLocalStoragePath()+subdirectory+"Project.json", file, 0644)
|
||||
|
||||
return err == nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user