-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storing face-tags to events.db and database
- Loading branch information
Showing
21 changed files
with
400 additions
and
218 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
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,9 +1,10 @@ | ||
import { Rect } from '@home-gallery/events' | ||
|
||
export interface Tag { | ||
name: string; | ||
remove: boolean; | ||
} | ||
|
||
export interface FaceTag extends Tag { | ||
descriptorIndex: number; | ||
} | ||
|
||
rect: Rect; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import * as React from "react"; | ||
|
||
import { Tag, FaceTag } from "../api/models"; | ||
|
||
import { MultiTagDialog, SingleTagDialog } from './tag-dialog' | ||
import { MultiFaceTagDialog, SingleFaceTagDialog } from './face-tag-dialog' | ||
|
||
export type TagsConfig = { | ||
initialTags?: Tag[]; | ||
onTagsSubmit: ({ tags }: { tags: Tag[] }) => void; | ||
} | ||
|
||
export type FaceTagsConfig = { | ||
initialFaceTags?: FaceTag[]; | ||
onFaceTagsSubmit: ({ faceTags }: { faceTags: FaceTag[] }) => void; | ||
} | ||
|
||
export type DialogConfig = { | ||
tagsConfig?: TagsConfig; | ||
faceTagsConfig?: FaceTagsConfig; | ||
} | ||
|
||
const initialTagsConfig: TagsConfig = { | ||
initialTags: [], | ||
onTagsSubmit: () => false, | ||
} | ||
|
||
const initialFaceTagsConfig: FaceTagsConfig = { | ||
initialFaceTags: [], | ||
onFaceTagsSubmit: () => false | ||
} | ||
|
||
export type DialogContextType = { | ||
setTagsDialogVisible: (visible: boolean) => void; | ||
openTagsDialog: ({ initialTags, onTagsSubmit }: TagsConfig) => void | ||
|
||
setFaceTagsDialogVisible: (visible: boolean) => void; | ||
openFaceTagsDialog: ({ initialFaceTags, onFaceTagsSubmit }: FaceTagsConfig) => void | ||
} | ||
|
||
const initialDialogContextValue: DialogContextType = { | ||
setTagsDialogVisible: () => false, | ||
openTagsDialog: () => false, | ||
|
||
setFaceTagsDialogVisible: () => false, | ||
openFaceTagsDialog: () => false | ||
} | ||
|
||
export const DialogContext = React.createContext<DialogContextType>(initialDialogContextValue) | ||
|
||
export const MultiTagDialogProvider = ({ children }) => { | ||
const [tagsDialogVisible, setTagsDialogVisible] = React.useState(false); | ||
const [facesDialogVisible, setFaceTagsDialogVisible] = React.useState(false); | ||
|
||
const [tagsConfig, setTagsConfig] = React.useState<TagsConfig>(initialTagsConfig); | ||
const [faceTagsConfig, setFaceTagsConfig] = React.useState<FaceTagsConfig>(initialFaceTagsConfig); | ||
|
||
const openTagsDialog = (tagsConfig: TagsConfig) => { | ||
setTagsDialogVisible(true); | ||
setFaceTagsDialogVisible(false); | ||
|
||
setTagsConfig((prev) => ({ ...prev, ...tagsConfig })); | ||
}; | ||
|
||
const onTagsSubmit = ({ tags }) => { | ||
tagsConfig.onTagsSubmit({ tags }) | ||
} | ||
|
||
const openFaceTagsDialog = (faceTagsConfig: FaceTagsConfig) => { | ||
setTagsDialogVisible(true); | ||
setFaceTagsDialogVisible(false); | ||
|
||
setFaceTagsConfig((prev) => ({ ...prev, ...faceTagsConfig })); | ||
}; | ||
|
||
const onFaceTagsSubmit = ({ faceTags }) => { | ||
faceTagsConfig.onFaceTagsSubmit({ faceTags }) | ||
} | ||
|
||
return ( | ||
<DialogContext.Provider value={{ setTagsDialogVisible, openTagsDialog, setFaceTagsDialogVisible, openFaceTagsDialog }}> | ||
{children} | ||
{tagsDialogVisible && ( | ||
<MultiTagDialog onSubmit={onTagsSubmit} onCancel={() => setTagsDialogVisible(false)}></MultiTagDialog> | ||
)} | ||
{ facesDialogVisible && ( | ||
<MultiFaceTagDialog onSubmit={onFaceTagsSubmit} onCancel={() => setFaceTagsDialogVisible(false)}></MultiFaceTagDialog> | ||
)} | ||
</DialogContext.Provider> | ||
) | ||
} | ||
|
||
export const SingleTagDialogProvider = ({ children }) => { | ||
const [tagsDialogVisible, setTagsDialogVisible] = React.useState(false); | ||
const [facesDialogVisible, setFaceTagsDialogVisible] = React.useState(false); | ||
|
||
const [tagsConfig, setTagsConfig] = React.useState<TagsConfig>(initialTagsConfig); | ||
const [faceTagsConfig, setFaceTagsConfig] = React.useState<FaceTagsConfig>(initialFaceTagsConfig); | ||
|
||
|
||
const openTagsDialog = ({ initialTags, onTagsSubmit }: TagsConfig) => { | ||
setTagsDialogVisible(true); | ||
setFaceTagsDialogVisible(false); | ||
|
||
setTagsConfig({ initialTags, onTagsSubmit }); | ||
}; | ||
|
||
const openFaceTagsDialog = ({ initialFaceTags, onFaceTagsSubmit }: FaceTagsConfig) => { | ||
setTagsDialogVisible(false); | ||
setFaceTagsDialogVisible(true); | ||
|
||
setFaceTagsConfig({ initialFaceTags, onFaceTagsSubmit }); | ||
}; | ||
|
||
const onTagsSubmit = ({ tags }) => { | ||
tagsConfig.onTagsSubmit({ tags }) | ||
} | ||
|
||
const onFaceTagsSubmit = ({ faceTags }) => { | ||
faceTagsConfig.onFaceTagsSubmit({ faceTags }) | ||
} | ||
|
||
|
||
return ( | ||
<DialogContext.Provider value={{ setTagsDialogVisible, openTagsDialog, setFaceTagsDialogVisible, openFaceTagsDialog }}> | ||
{children} | ||
{tagsDialogVisible && ( | ||
<SingleTagDialog tags={tagsConfig.initialTags || []} onSubmit={onTagsSubmit} onCancel={() => setTagsDialogVisible(false)}></SingleTagDialog> | ||
)} | ||
{facesDialogVisible && ( | ||
<SingleFaceTagDialog faceTags={faceTagsConfig.initialFaceTags || []} onSubmit={onFaceTagsSubmit} onCancel={() => setFaceTagsDialogVisible(false)}></SingleFaceTagDialog> | ||
)} | ||
</DialogContext.Provider> | ||
) | ||
} | ||
|
||
|
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
Oops, something went wrong.