Skip to content

Instantly share code, notes, and snippets.

View gpDA's full-sized avatar
🏠
Working from home

GP LEE gpDA

🏠
Working from home
View GitHub Profile
@gpDA
gpDA / aws3.js
Created September 10, 2019 16:57
handleLogInSubmit = () => {
Auth.SignIn(email, password)
.then((response) => {
localStorage.setItem('isLogged', true)
})
}
@gpDA
gpDA / aws4.js
Created September 10, 2019 17:01
const PrivateRoute = ({component: Component, ...rest}) => {
return(
<Route {...rest} render={props => (
localStorage.getItem('isLogged') === 'true' ?
<Component {...props} />
: <Redirect to="/login" />
)}
/>
)
}
@gpDA
gpDA / aws5.js
Created September 10, 2019 17:04
signOut = () => {
const { history } = this.props
Auth.signOut()
.then(() => {
localStorage.clear()
history.push('/login')
})
.catch(err => console.log(err))
@gpDA
gpDA / aws6.js
Created September 10, 2019 17:14
<IdleTimer
onIdle={this.onIdle}
timeout={1000 * 60 * 30}
/>
onIdle = () => {
alert("You have been idle for 30 minutes and have been logged out.");
this.signOut();
}
// store/modules/base.js
...
[SORT_TYPE]: (state, action) => {
const {reportType, sortType, level} = action.payload
...
return state.set('sortType', reportType + sortType + level)
onSortClick = (sortType) => {
const {BaseActions} = this.props
BaseActions.sortType({sortType, reportType: 'uniqueReportType', level: 'studentData'})
}
...
render(){
const {onSortClick} = this
return (
<React.Fragment>
<Table>
<thead>
<tr>
<th onClick={() => handleSortClick("studentId")}>
<strong>
studentId
{arrowToggle === -1 && sortType === "uniqueReportTypestudentIdstudentData" ? (
<>&#8595;</>
// TableUI.js
class TableUI extends Component{
handleSortClick = sortType => {
const {onSortClick} = this.props;
onSortClick(sortType)
}
render(){
// SmartSort.js
class SmartSort extends Component{
onSortClick = sortType => {
const { BaseActions } = this.props;
BaseActions.sortType({ sortType })
}
}
// store/modules/base.js
// initial state
const initialState = Map({
mainData: List(... ),
originalData: List(... ),
arrowToggle: 0,
sortType: "",
sortToggle: false
});