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,
|
selectedAreaId,
|
||||||
isEditAreaNameInputShowing,
|
isEditAreaNameInputShowing,
|
||||||
setIsEditAreaNameInputShowing,
|
setIsEditAreaNameInputShowing,
|
||||||
|
dragOverAreaId,
|
||||||
|
setDragOverAreaId,
|
||||||
} = useSidebar()
|
} = useSidebar()
|
||||||
|
|
||||||
const editAreaNameTextInput = useRef<HTMLInputElement>(null)
|
const editAreaNameTextInput = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const [dragOverAreaId, setDragOverAreaId] = useState('')
|
|
||||||
|
|
||||||
const onConfirmAreaNameChangeHandler = async (areaDetails: { areaId: string, areaName: string }) => {
|
const onConfirmAreaNameChangeHandler = async (areaDetails: { areaId: string, areaName: string }) => {
|
||||||
const { areaId, areaName } = areaDetails
|
const { areaId, areaName } = areaDetails
|
||||||
@ -66,6 +67,8 @@ const AreaLineItem = (props: { area: SidebarArea, documentId: string, index: num
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onAreaDropEnd = (areaId: string) => {
|
const onAreaDropEnd = (areaId: string) => {
|
||||||
|
if (!areaId || areaId == dragOverAreaId) return
|
||||||
|
|
||||||
const areaDroppedOn = getAreaById(dragOverAreaId)
|
const areaDroppedOn = getAreaById(dragOverAreaId)
|
||||||
console.log(areaDroppedOn)
|
console.log(areaDroppedOn)
|
||||||
if (!areaDroppedOn) return
|
if (!areaDroppedOn) return
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { SidebarGroup } from './types'
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const GroupLineItem = (props: { group: SidebarGroup }) => {
|
const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => {
|
||||||
const {
|
const {
|
||||||
requestAddDocument,
|
requestAddDocument,
|
||||||
requestChangeGroupOrder,
|
requestChangeGroupOrder,
|
||||||
@ -26,12 +26,12 @@ const GroupLineItem = (props: { group: SidebarGroup }) => {
|
|||||||
setSelectedGroupId,
|
setSelectedGroupId,
|
||||||
setIsAddNewDocumentInputShowing,
|
setIsAddNewDocumentInputShowing,
|
||||||
setIsAddNewGroupInputShowing,
|
setIsAddNewGroupInputShowing,
|
||||||
|
dragOverGroupId,
|
||||||
|
setDragOverGroupId
|
||||||
} = useSidebar()
|
} = useSidebar()
|
||||||
|
|
||||||
const addDocumentTextInput = useRef<HTMLInputElement>(null)
|
const addDocumentTextInput = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const [dragOverGroupId, setDragOverGroupId] = useState('')
|
|
||||||
|
|
||||||
const onConfirmAddDocumentClickHandler = async (groupId: string) => {
|
const onConfirmAddDocumentClickHandler = async (groupId: string) => {
|
||||||
const documentName = addDocumentTextInput.current?.value
|
const documentName = addDocumentTextInput.current?.value
|
||||||
if (!documentName) return
|
if (!documentName) return
|
||||||
@ -63,10 +63,12 @@ const GroupLineItem = (props: { group: SidebarGroup }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onGroupDropEnd = (groupId: string) => {
|
const onGroupDropEnd = (groupId: string) => {
|
||||||
const areaDroppedOn = getGroupById(groupId)
|
if (!groupId || groupId == dragOverGroupId) return
|
||||||
console.log('areaDroppedOn', areaDroppedOn)
|
|
||||||
if (!areaDroppedOn) return
|
const groupDroppedOn = getGroupById(dragOverGroupId)
|
||||||
const response = requestChangeGroupOrder(groupId, areaDroppedOn.order)
|
console.log('groupDroppedOn', groupDroppedOn)
|
||||||
|
if (!groupDroppedOn) return
|
||||||
|
requestChangeGroupOrder(groupId, groupDroppedOn.order)
|
||||||
setDragOverGroupId('')
|
setDragOverGroupId('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useProject } from '../../../context/Project/provider'
|
import { useProject } from '../../../context/Project/provider'
|
||||||
import AddGroupInput from './AddGroupInput'
|
import AddGroupInput from './AddGroupInput'
|
||||||
import GroupLineItem from './GroupLineItem'
|
import GroupLineItem from './GroupLineItem'
|
||||||
|
|||||||
@ -19,6 +19,9 @@ export function SidebarProvider({ children }: Props) {
|
|||||||
const [isEditDocumentNameInputShowing, setIsEditDocumentNameInputShowing] = useState(false)
|
const [isEditDocumentNameInputShowing, setIsEditDocumentNameInputShowing] = useState(false)
|
||||||
const [isAddNewGroupInputShowing, setIsAddNewGroupInputShowing] = useState(false)
|
const [isAddNewGroupInputShowing, setIsAddNewGroupInputShowing] = useState(false)
|
||||||
const [isEditAreaNameInputShowing, setIsEditAreaNameInputShowing] = useState(false)
|
const [isEditAreaNameInputShowing, setIsEditAreaNameInputShowing] = useState(false)
|
||||||
|
const [dragOverGroupId, setDragOverGroupId] = useState('')
|
||||||
|
const [dragOverAreaId, setDragOverAreaId] = useState('')
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
selectedDocumentId, setSelectedDocumentId,
|
selectedDocumentId, setSelectedDocumentId,
|
||||||
@ -44,7 +47,11 @@ export function SidebarProvider({ children }: Props) {
|
|||||||
isAddNewGroupInputShowing,
|
isAddNewGroupInputShowing,
|
||||||
setIsAddNewGroupInputShowing,
|
setIsAddNewGroupInputShowing,
|
||||||
isEditAreaNameInputShowing,
|
isEditAreaNameInputShowing,
|
||||||
setIsEditAreaNameInputShowing
|
setIsEditAreaNameInputShowing,
|
||||||
|
dragOverGroupId,
|
||||||
|
setDragOverGroupId,
|
||||||
|
dragOverAreaId,
|
||||||
|
setDragOverAreaId,
|
||||||
}
|
}
|
||||||
|
|
||||||
return <SidebarContext.Provider value={value}>
|
return <SidebarContext.Provider value={value}>
|
||||||
|
|||||||
@ -14,6 +14,10 @@ export type SidebarContextType = {
|
|||||||
setIsAddNewGroupInputShowing: (_: boolean) => void,
|
setIsAddNewGroupInputShowing: (_: boolean) => void,
|
||||||
isEditAreaNameInputShowing: boolean,
|
isEditAreaNameInputShowing: boolean,
|
||||||
setIsEditAreaNameInputShowing: (_: boolean) => void,
|
setIsEditAreaNameInputShowing: (_: boolean) => void,
|
||||||
|
dragOverGroupId: string,
|
||||||
|
setDragOverGroupId: (_: string) => void,
|
||||||
|
dragOverAreaId: string,
|
||||||
|
setDragOverAreaId: (_: string) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SidebarArea = {
|
export type SidebarArea = {
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import {
|
|||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
||||||
import makeDefaultProject from './makeDefaultProject'
|
import makeDefaultProject from './makeDefaultProject'
|
||||||
|
import { saveDocuments, saveGroups } from '../../useCases/saveData'
|
||||||
|
|
||||||
const ProjectContext = createContext<ProjectContextType>(makeDefaultProject())
|
const ProjectContext = createContext<ProjectContextType>(makeDefaultProject())
|
||||||
|
|
||||||
@ -33,25 +34,11 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
const [selectedDocumentId, setSelectedDocumentId] = useState<string>('')
|
const [selectedDocumentId, setSelectedDocumentId] = useState<string>('')
|
||||||
const [currentSession, setCurrentSession] = useState<ipc.Session>(new ipc.Session())
|
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 () => {
|
const updateDocuments = async () => {
|
||||||
GetDocuments().then(response => {
|
GetDocuments().then(response => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.documents.length) setDocuments(response.documents)
|
if (response.documents.length) setDocuments(response.documents)
|
||||||
if (response.groups.length) setGroups(response.groups)
|
if (response.groups.length) setGroups(response.groups)
|
||||||
saveDocumentsAndGroups()
|
|
||||||
Promise.resolve(response)
|
Promise.resolve(response)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -59,18 +46,21 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
const requestAddDocument = async (groupId: string, documentName: string) => {
|
const requestAddDocument = async (groupId: string, documentName: string) => {
|
||||||
const response = await RequestAddDocument(groupId, documentName)
|
const response = await RequestAddDocument(groupId, documentName)
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestAddDocumentGroup = async (groupName: string) => {
|
const requestAddDocumentGroup = async (groupName: string) => {
|
||||||
const response = await RequestAddDocumentGroup(groupName)
|
const response = await RequestAddDocumentGroup(groupName)
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
|
saveGroups()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<ipc.Area> => {
|
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<ipc.Area> => {
|
||||||
const response = await RequestAddArea(documentId, new ipc.Area(area))
|
const response = await RequestAddArea(documentId, new ipc.Area(area))
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +68,7 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
const response = await RequestUpdateArea(new ipc.Area(updatedArea))
|
const response = await RequestUpdateArea(new ipc.Area(updatedArea))
|
||||||
|
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +79,7 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
const requestDeleteAreaById = async (areaId: string): Promise<boolean> => {
|
const requestDeleteAreaById = async (areaId: string): Promise<boolean> => {
|
||||||
const wasSuccessfulDeletion = await RequestDeleteAreaById(areaId)
|
const wasSuccessfulDeletion = await RequestDeleteAreaById(areaId)
|
||||||
if (wasSuccessfulDeletion) updateDocuments()
|
if (wasSuccessfulDeletion) updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return wasSuccessfulDeletion
|
return wasSuccessfulDeletion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,12 +146,14 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
const requestUpdateDocument = async (docuemntProps: UpdateDocumentRequest) => {
|
const requestUpdateDocument = async (docuemntProps: UpdateDocumentRequest) => {
|
||||||
const response = await RequestUpdateDocument(new ipc.Document(docuemntProps))
|
const response = await RequestUpdateDocument(new ipc.Document(docuemntProps))
|
||||||
await updateDocuments()
|
await updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestChangeAreaOrder = async (areaId: string, newOrder: number) => {
|
const requestChangeAreaOrder = async (areaId: string, newOrder: number) => {
|
||||||
const response = await RequestChangeAreaOrder(areaId, newOrder)
|
const response = await RequestChangeAreaOrder(areaId, newOrder)
|
||||||
await updateDocuments()
|
await updateDocuments()
|
||||||
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +163,10 @@ export function ProjectProvider({ children, projectProps }: Props) {
|
|||||||
|
|
||||||
const requestChangeGroupOrder = async (groupId: string, newOrder: number) => {
|
const requestChangeGroupOrder = async (groupId: string, newOrder: number) => {
|
||||||
const response = await RequestChangeGroupOrder(groupId, newOrder)
|
const response = await RequestChangeGroupOrder(groupId, newOrder)
|
||||||
|
console.log('should be at ', newOrder)
|
||||||
|
console.log(response)
|
||||||
await updateDocuments()
|
await updateDocuments()
|
||||||
|
saveGroups()
|
||||||
return response
|
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 {
|
for index, a := range documentOfArea.Areas {
|
||||||
if a.Id == areaId {
|
if a.Id == areaId {
|
||||||
documentOfArea.Areas[index].Order = newOrder
|
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 {
|
} else if a.Order >= newOrder {
|
||||||
documentOfArea.Areas[index].Order = a.Order + 1
|
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{
|
successfulProjectWrite := storage.WriteLocalProjectData(storage.LocalProject{
|
||||||
Id: uuid.NewString(),
|
Id: newProject.Id,
|
||||||
OrganizationId: currentSession.Project.OrganizationId,
|
OrganizationId: newProject.OrganizationId,
|
||||||
Name: name,
|
Name: newProject.Name,
|
||||||
})
|
})
|
||||||
|
|
||||||
if !successfulProjectWrite {
|
if !successfulProjectWrite {
|
||||||
|
|||||||
@ -30,7 +30,7 @@ func createLocalStorageDirIfNeeded() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorCreatingDir := os.Mkdir(localStoragePath, os.ModePerm)
|
errorCreatingDir := os.Mkdir(localStoragePath, os.ModePerm)
|
||||||
return errorCreatingDir != nil
|
return errorCreatingDir == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLocalStorageSubDirIfNeeded(relativeSubdirectoryPath string) bool {
|
func createLocalStorageSubDirIfNeeded(relativeSubdirectoryPath string) bool {
|
||||||
@ -48,7 +48,7 @@ func createLocalStorageSubDirIfNeeded(relativeSubdirectoryPath string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorCreatingDir := os.MkdirAll(fullLocalStoragePath, os.ModePerm)
|
errorCreatingDir := os.MkdirAll(fullLocalStoragePath, os.ModePerm)
|
||||||
return errorCreatingDir != nil
|
return errorCreatingDir == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteLocalUserData(user LocalUser) bool {
|
func WriteLocalUserData(user LocalUser) bool {
|
||||||
@ -110,13 +110,15 @@ func WriteLocalProjectData(project LocalProject) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(project)
|
||||||
|
|
||||||
subdirectory := "/projects/" + project.Name + "/"
|
subdirectory := "/projects/" + project.Name + "/"
|
||||||
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
||||||
if !isLocalStorageDirectoryCreated {
|
if !isLocalStorageDirectoryCreated {
|
||||||
return false
|
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
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user