Skip to content

Commit

Permalink
feat(lb-components): Add skipBeforePageTurning
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin-L committed Aug 30, 2022
1 parent b7347ee commit 12673fe
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/lb-components/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export interface AppProps {
defaultLang: 'en' | 'cn'; // 国际化设置
leftSider?: () => React.ReactNode | React.ReactNode;

// data Correction
skipBeforePageTurning?: (pageTurning: Function) => void;

// 标注信息扩展的功能
dataInjectionAtCreation: (annotationData: any) => {};
// 渲染增强
Expand Down Expand Up @@ -87,6 +90,7 @@ const App: React.FC<AppProps> = (props) => {
pageSize = 10,
loadFileList,
defaultLang = 'cn',
skipBeforePageTurning,
} = props;

useEffect(() => {
Expand All @@ -101,6 +105,7 @@ const App: React.FC<AppProps> = (props) => {
onSave,
onPageChange,
onStepChange,
skipBeforePageTurning,
}),
);

Expand Down
18 changes: 16 additions & 2 deletions packages/lb-components/src/components/customResizeHook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export const viewportContext = React.createContext<{
});

export const ViewportProviderComponent = (props: any) => {
const { children, dispatch } = props;
const {
children,
dispatch,
annotation: { skipBeforePageTurning },
} = props;
console.log('viewport', props);
const [width] = useState(window.innerWidth);
const [height] = useState(window.innerHeight);

Expand All @@ -40,10 +45,19 @@ export const ViewportProviderComponent = (props: any) => {

if (!e.shiftKey || !e.ctrlKey) {
if (e.keyCode === EKeyCode.A) {
if (skipBeforePageTurning) {
skipBeforePageTurning(() => dispatch(PageBackward()));
return;
}

dispatch(PageBackward());
}

if (e.keyCode === EKeyCode.D) {
if (skipBeforePageTurning) {
skipBeforePageTurning(() => dispatch(PageForward()));
return;
}
dispatch(PageForward());
}
if (e.keyCode === EKeyCode.R) {
Expand Down Expand Up @@ -77,7 +91,7 @@ export const ViewportProviderComponent = (props: any) => {
return () => {
window.removeEventListener('keydown', keydown);
};
}, [props.annotation.annotationEngine]);
}, [props.annotation.annotationEngine, props.annotation.skipBeforePageTurning]);

const size = useMemo(() => ({ width, height }), [width, height]);

Expand Down
2 changes: 1 addition & 1 deletion packages/lb-components/src/store/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ANNOTATION_ACTIONS = {
SET_BASIC_INDEX: '@@SET_BASIC_INDEX',
CALC_STEP_PROGRESS: '@@CALC_STEP_PROGRESS',
SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED: '@@SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED',

SKIP_BEFORE_PAGE_TURNING: '@@SKIP_BEFORE_PAGE_TURNING',
SET_LOADING: '@@SET_LOADING',
};

Expand Down
15 changes: 15 additions & 0 deletions packages/lb-components/src/store/annotation/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export function UpdateRotate(): AnnotationActionTypes {
};
}

export function UpdateSkipBeforePageTurning(skipBeforePageTurning: (pageTurning: Function) => {}): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING,
payload: {
skipBeforePageTurning,
},
};
}

export function CopyBackWordResult(): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT,
Expand All @@ -178,6 +187,7 @@ export function InitTaskData({
loadFileList,
step,
stepList,
skipBeforePageTurning
}: any): any {
const tasks: any[] = [];

Expand Down Expand Up @@ -207,6 +217,10 @@ export function InitTaskData({
tasks.push(UpdatePageSize(pageSize));
}

if (skipBeforePageTurning) {
tasks.push(UpdateSkipBeforePageTurning(skipBeforePageTurning));
}

tasks.push(SetTaskConfig({ stepList, step }));

tasks.push({
Expand Down Expand Up @@ -417,6 +431,7 @@ export const DispatcherTurning = async (
return;
}
}

annotationStore.onPageChange?.(fileIndex);
const index =
submitType === ESubmitType.Backward
Expand Down
7 changes: 7 additions & 0 deletions packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,13 @@ export const annotationReducer = (
};
}

case ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING: {
return {
...state,
skipBeforePageTurning: action.payload.skipBeforePageTurning,
};
}

case ANNOTATION_ACTIONS.SET_FILE_DATA: {
const { fileData, index } = action.payload;
const { imgList } = state;
Expand Down
3 changes: 3 additions & 0 deletions packages/lb-components/src/store/annotation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface CommonActions {
payload?: any;
}


export interface AnnotationState {
toolInstance: ToolInstance | null;
annotationEngine: AnnotationEngine | null;
Expand All @@ -57,6 +58,8 @@ export interface AnnotationState {
loading: boolean; // 用于图片加载
/** 阻止文件切换后的事件 */
triggerEventAfterIndexChanged: boolean;

skipBeforePageTurning?: (pageTurning: Function) => void;
}

interface UpdateToolInstance {
Expand Down
13 changes: 13 additions & 0 deletions packages/lb-components/src/views/MainView/toolFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface IProps {
basicIndex: number;
mode?: FooterTheme; // 后面通过 context 的形式进行编写
footer?: RenderFooter;

skipBeforePageTurning?: (pageTurning: Function) => void;
}

export const footerCls = `${prefix}-footer`;
Expand Down Expand Up @@ -72,6 +74,7 @@ const ToolFooter: React.FC<IProps> = (props: IProps) => {
basicIndex,
mode = 'light',
footer = renderFooter,
skipBeforePageTurning,
} = props;

const dispatch = useDispatch();
Expand All @@ -80,10 +83,19 @@ const ToolFooter: React.FC<IProps> = (props: IProps) => {
const hasSourceStep = !!stepInfo.dataSourceStep;

const pageBackward = () => {
if (skipBeforePageTurning) {
skipBeforePageTurning(() => dispatch(PageBackward()));
return;
}

dispatch(PageBackward());
};

const pageForward = () => {
if (skipBeforePageTurning) {
skipBeforePageTurning(() => dispatch(PageForward()));
return;
}
dispatch(PageForward());
};

Expand Down Expand Up @@ -144,6 +156,7 @@ const mapStateToProps = (state: AppState) => ({
step: state.annotation.step,
basicIndex: state.annotation.basicIndex,
basicResultList: state.annotation.basicResultList,
skipBeforePageTurning: state.annotation.skipBeforePageTurning,
});

export default connect(mapStateToProps)(ToolFooter);

0 comments on commit 12673fe

Please sign in to comment.