Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Made a lock all button #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const toggleLock = createStandardAction('TOGGLE_LOCK')<number>();

export const unlockAll = createStandardAction('UNLOCK_ALL')();

export const lockAll = createStandardAction('LOCK_ALL')();

export const selectCard = createStandardAction('SELECT_CARD')<number>();
19 changes: 16 additions & 3 deletions src/containers/randomizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import { AllActions } from 'src/actions';
import CardInfoPane from 'src/components/card-info-pane';
import CardsList from 'src/components/cards-list';
import { IRootState } from 'src/reducers';
import { canRedo, canUndo } from 'src/selectors/undo.selectors';
import { canRedo, canUndo, allUnlocked } from 'src/selectors/undo.selectors';
import '../styles/randomizer.scss';
import '../styles/button.scss';
import classNames from 'classnames';

interface IRandomizerProps {
randomize: () => void;
unlockAll: () => void;
lockAll: () => void;
undo: () => void;
redo: () => void;

canUndo: boolean;
canRedo: boolean;
allUnlocked: boolean;
}

const Component: React.SFC<IRandomizerProps> = props => (
Expand All @@ -30,11 +32,21 @@ const Component: React.SFC<IRandomizerProps> = props => (
<span>Randomize</span>
</span>
<span
className='btn-container btn btn-one'
className={classNames('btn-container btn btn-one', {
hidden: props.allUnlocked
})}
onClick={props.unlockAll}
>
<span>Unlock All</span>
</span>
<span
className={classNames('btn-container btn btn-one', {
hidden: !props.allUnlocked
})}
onClick={props.lockAll}
>
<span>Lock All</span>
</span>
<span
className={classNames('btn-container btn btn-one', {
disabled: !props.canUndo
Expand Down Expand Up @@ -62,7 +74,8 @@ const Component: React.SFC<IRandomizerProps> = props => (
const Randomizer = connect(
(state: IRootState) => ({
canUndo: canUndo(state),
canRedo: canRedo(state)
canRedo: canRedo(state),
allUnlocked: allUnlocked(state)
}),
dispatch => bindActionCreators({ ...AllActions }, dispatch)
)(Component);
Expand Down
5 changes: 5 additions & 0 deletions src/reducers/cards-list.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function cardsList(
...state,
lockedCards: ImmutableSet()
};
case getType(AllActions.lockAll):
return {
...state,
lockedCards: ImmutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
};
case getType(AllActions.randomize):
case getType(AllActions.redo):
case getType(AllActions.undo):
Expand Down
3 changes: 3 additions & 0 deletions src/selectors/undo.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export const canUndo = (state: IRootState) =>

export const canRedo = (state: IRootState) =>
state.cardsList.currentCards.future.length > 0;

export const allUnlocked = (state: IRootState) =>
state.cardsList.lockedCards.size === 0;
52 changes: 28 additions & 24 deletions src/styles/button.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import './theme';

.btn-container {
.btn-container {
margin-top: 2em;
margin-bottom: 2em;
background: $btn-background;
Expand All @@ -12,7 +12,7 @@
width: 100%;
height: 33%;
border-radius: 5px;
align-items: center;
align-items: center;
}

.btn {
Expand All @@ -23,12 +23,13 @@
line-height: 64px;
transition: all 0.3s;
span {
transition: all 0.3s;
transform: scale(1, 1);
transition: all 0.3s;
transform: scale(1, 1);
}
}

.btn:not(.disabled)::before, .btn:not(.disabled)::after {
}

.btn:not(.disabled)::before,
.btn:not(.disabled)::after {
content: '';
position: absolute;
transition: all 0.3s;
Expand All @@ -37,33 +38,36 @@
width: 100%;
height: 100%;
z-index: 1;
}
.btn-one:not(.disabled)::before {
}

.btn-one:not(.disabled)::before {
left: 4px;
z-index: 1;
opacity: 0;
background: rgba(255, 255, 255, 0.1);
transform: scale(0.1, 1);
}
.btn-one:not(.disabled):hover::before {
}

.btn-one:not(.disabled):hover::before {
opacity: 1;
transform: scale(1, 1);
}
.btn-one:not(.disabled)::after {
}

.btn-one:not(.disabled)::after {
transition: all 0.3s;
border: 0px solid rgba(255, 255, 255, 0.5);
}
.btn-one:not(.disabled):hover::after {
transform: scale(1, .1);
}

.btn-one:not(.disabled):hover::after {
transform: scale(1, 0.1);
opacity: 0;
}
}

.btn-one.disabled {
.btn-one.disabled {
background: #aaa;
color: #555;

}
}

.btn-one.hidden {
display: none;
}