-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from IDEA-Research/feature/annotator_update
Feature/annotator update
- Loading branch information
Showing
136 changed files
with
9,236 additions
and
3,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,10 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import React from 'react'; | ||
import QuickLabel from 'dds-components/QuickLabel'; | ||
import { useModel } from '@umijs/max'; | ||
import styles from './index.less'; | ||
import { AnnotateEditor, EditorMode } from 'dds-components/Annotator'; | ||
import { ImageList } from './components/ImageList'; | ||
import { Button } from 'antd'; | ||
import { SettingOutlined } from '@ant-design/icons'; | ||
import { FormModal } from './components/FormModal'; | ||
import { useLocale } from 'dds-utils/locale'; | ||
import { useKeyPress } from 'ahooks'; | ||
import { BaseObject } from '@/types'; | ||
|
||
const Page: React.FC = () => { | ||
const { | ||
images, | ||
setImages, | ||
current, | ||
setCurrent, | ||
categories, | ||
setCategories, | ||
exportAnnotations, | ||
} = useModel('Annotator.model'); | ||
|
||
const { localeText } = useLocale(); | ||
const [openModal, setModalOpen] = useState(true); | ||
|
||
useEffect(() => { | ||
// const handleBeforeUnload = (event: BeforeUnloadEvent) => { | ||
// event.preventDefault(); | ||
// event.returnValue = | ||
// 'The current changes will not be saved. Please export before leaving.'; | ||
// }; | ||
// window.addEventListener('beforeunload', handleBeforeUnload); | ||
// return () => { | ||
// window.removeEventListener('beforeunload', handleBeforeUnload); | ||
// }; | ||
}, []); | ||
|
||
// local test | ||
useEffect( | ||
() => { | ||
// if(images.length > 0 && categories.length > 0) { | ||
// localStorage.setItem('images', JSON.stringify(images)); | ||
// localStorage.setItem('categories', JSON.stringify(categories)); | ||
// console.log('>>> save localStorage'); | ||
// } | ||
const images = localStorage.getItem('images'); | ||
const categories = localStorage.getItem('categories'); | ||
if (images && categories) { | ||
setImages(JSON.parse(images)); | ||
setCategories(JSON.parse(categories)); | ||
setModalOpen(false); | ||
} | ||
}, | ||
// [images, categories] | ||
[], | ||
); | ||
|
||
useKeyPress( | ||
'uparrow', | ||
() => { | ||
setCurrent(Math.max(0, current - 1)); | ||
}, | ||
{ exactMatch: true }, | ||
); | ||
|
||
useKeyPress( | ||
'downarrow', | ||
() => { | ||
setCurrent(Math.min(current + 1, images.length - 1)); | ||
}, | ||
{ exactMatch: true }, | ||
); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div | ||
className={styles.left} | ||
onMouseDown={(event) => { | ||
event.stopPropagation(); | ||
}} | ||
onMouseUp={(event) => { | ||
event.stopPropagation(); | ||
}} | ||
> | ||
<Button | ||
type="primary" | ||
icon={<SettingOutlined />} | ||
onClick={() => { | ||
setModalOpen(true); | ||
}} | ||
> | ||
{localeText('annotator.setting')} | ||
</Button> | ||
<ImageList | ||
images={images} | ||
selected={current} | ||
onImageSelected={(index) => { | ||
setCurrent(index); | ||
}} | ||
/> | ||
</div> | ||
<div className={styles.right}> | ||
<AnnotateEditor | ||
isSeperate={true} | ||
visible={true} | ||
mode={EditorMode.Edit} | ||
categories={categories} | ||
setCategories={setCategories} | ||
list={images} | ||
current={current} | ||
actionElements={[ | ||
<Button type="primary" key={'export'} onClick={exportAnnotations}> | ||
{localeText('annotator.export')} | ||
</Button>, | ||
]} | ||
onAutoSave={(annos: BaseObject[], naturalSize: ISize) => { | ||
setImages((images) => { | ||
if (images[current]) { | ||
images[current].objects = annos; | ||
images[current].width = naturalSize.width; | ||
images[current].height = naturalSize.height; | ||
} | ||
}); | ||
}} | ||
/> | ||
</div> | ||
<div | ||
className={styles.modal} | ||
onMouseDown={(e) => e.stopPropagation()} | ||
onMouseUp={(e) => e.stopPropagation()} | ||
> | ||
<FormModal open={openModal} setOpen={setModalOpen} /> | ||
</div> | ||
</div> | ||
); | ||
const props = useModel('Annotator.model'); | ||
return <QuickLabel {...props} />; | ||
}; | ||
|
||
export default Page; |
Oops, something went wrong.