Skip to content

Commit

Permalink
Remove empty interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Apr 17, 2020
1 parent 0ff258a commit 016242c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = {
'no-duplicate-imports': 'off',
'react/display-name': 'off',
'prettier/prettier': 'error',
'@typescript-eslint/no-empty-interface': 'off'
'@typescript-eslint/no-empty-interface': 'error'
}
};
5 changes: 0 additions & 5 deletions src/containers/GalleryContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ interface IGalleryContainerProps {
dispatch: Dispatch<IGalleryAction> & TGalleryThunkDispatch;
}

interface IGalleryContainerState {
isDrawerOpen: boolean;
isSearchByPopularity: boolean;
}

const GalleryContainer: React.FunctionComponent<IGalleryContainerProps> = () => {
const classes = useStyles();
const intl = useIntl();
Expand Down
4 changes: 1 addition & 3 deletions src/containers/IllustContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ interface IIllustContainerRouteInfo {
illustId: string;
}

interface IIllustContainerProps {}

const IllustContainer: React.FunctionComponent<IIllustContainerProps> = () => {
const IllustContainer: React.FunctionComponent<{}> = () => {
const [isSubmitting, setIsSubmitting] = React.useState(false);
const [boxIndex, setBoxIndex] = React.useState(0);
const [showBox, setShowBox] = React.useState(false);
Expand Down
215 changes: 106 additions & 109 deletions src/containers/LoginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Login, { ILoginHandles } from '@/components/Login';

import { ICombinedState } from '@/reducers';

interface ILoginContainerProps {}

export interface ILoginContainerHandles {
open: () => void;
close: () => void;
Expand Down Expand Up @@ -39,119 +37,118 @@ export const UserButton = (props: IUserButtonProps) => {
);
};

const LoginContainer = React.forwardRef<
ILoginContainerHandles,
ILoginContainerProps
>((props, ref) => {
const [isSubmitting, setIsSubmitting] = React.useState(false);
const [authData, setAuthData] = React.useState<any>(null);
const intl = useIntl();
const dispatch = useDispatch();
const loginRef = React.useRef<ILoginHandles>(null);

React.useEffect(() => {
const authData = api.getAuth();
setAuthData(authData);
}, []);

const open = () => {
loginRef.current?.open();
};

const close = () => {
loginRef.current?.close();
};

const onLoginClick = () => {
if (isSubmitting || !loginRef.current?.getIsOpen()) {
return;
}

const username = loginRef.current?.getUsername();
const password = loginRef.current?.getPassword();

if (username === '') {
return AlertModal.make(
'error',
intl.formatMessage({
id: 'pixiv ID or Email Address is Blank'
})
);
}

if (password === '') {
return AlertModal.make(
'error',
intl.formatMessage({ id: 'Password is Blank' })
);
}

setIsSubmitting(true);

api
.auth({
username,
password
})
.then((data: any) => {
if (data.status === 'success') {
const authData = data.response;
api.setAuth(authData, dispatch);
setAuthData(authData);
setTimeout(() => {
close();
loginRef.current?.reset();
}, 1500);
} else {
AlertModal.make('error', data.message);
}
})
.then(() => {
setIsSubmitting(false);
})
.catch(() => {
setIsSubmitting(false);
AlertModal.make(
const LoginContainer = React.forwardRef<ILoginContainerHandles, {}>(
(props, ref) => {
const [isSubmitting, setIsSubmitting] = React.useState(false);
const [authData, setAuthData] = React.useState<any>(null);
const intl = useIntl();
const dispatch = useDispatch();
const loginRef = React.useRef<ILoginHandles>(null);

React.useEffect(() => {
const authData = api.getAuth();
setAuthData(authData);
}, []);

const open = () => {
loginRef.current?.open();
};

const close = () => {
loginRef.current?.close();
};

const onLoginClick = () => {
if (isSubmitting || !loginRef.current?.getIsOpen()) {
return;
}

const username = loginRef.current?.getUsername();
const password = loginRef.current?.getPassword();

if (username === '') {
return AlertModal.make(
'error',
intl.formatMessage({
id: 'Communication Error Occurred'
id: 'pixiv ID or Email Address is Blank'
})
);
});
};

const onLogoutClick = () => {
api.removeAuth(dispatch);
setAuthData(null);
};
}

const onKeydown = (event: KeyboardEvent) => {
if (loginRef.current?.getIsOpen() && event.keyCode === 13) {
onLoginClick();
}
};
if (password === '') {
return AlertModal.make(
'error',
intl.formatMessage({ id: 'Password is Blank' })
);
}

React.useImperativeHandle(ref, () => ({
open: () => open(),
close: () => close()
}));
setIsSubmitting(true);

return (
<>
<Login
ref={loginRef}
onLoginClick={onLoginClick}
onLogoutClick={onLogoutClick}
isSubmitting={isSubmitting}
authData={authData}
/>
<EventListener
target={document}
// @ts-ignore
onKeydown={onKeydown}
/>
</>
);
});
api
.auth({
username,
password
})
.then((data: any) => {
if (data.status === 'success') {
const authData = data.response;
api.setAuth(authData, dispatch);
setAuthData(authData);
setTimeout(() => {
close();
loginRef.current?.reset();
}, 1500);
} else {
AlertModal.make('error', data.message);
}
})
.then(() => {
setIsSubmitting(false);
})
.catch(() => {
setIsSubmitting(false);
AlertModal.make(
'error',
intl.formatMessage({
id: 'Communication Error Occurred'
})
);
});
};

const onLogoutClick = () => {
api.removeAuth(dispatch);
setAuthData(null);
};

const onKeydown = (event: KeyboardEvent) => {
if (loginRef.current?.getIsOpen() && event.keyCode === 13) {
onLoginClick();
}
};

React.useImperativeHandle(ref, () => ({
open: () => open(),
close: () => close()
}));

return (
<>
<Login
ref={loginRef}
onLoginClick={onLoginClick}
onLogoutClick={onLogoutClick}
isSubmitting={isSubmitting}
authData={authData}
/>
<EventListener
target={document}
// @ts-ignore
onKeydown={onKeydown}
/>
</>
);
}
);

export default LoginContainer;

0 comments on commit 016242c

Please sign in to comment.