Skip to content

Commit

Permalink
feat(client): hide history mobile records lines on swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozwiaczek committed Sep 4, 2021
1 parent b5df1e9 commit 81c39e9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
3 changes: 2 additions & 1 deletion packages/client/src/elements/Swipeout/Swipeout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Default.args = {
],
onOpen: () => console.log('onOpen'),
onClose: () => console.log('onClose'),
onSwipe: () => console.log('onSwipe'),
onSwipeStart: () => console.log('onSwipeStart'),
onSwipeEnd: () => console.log('onSwipeEnd'),
autoClose: true,
disabled: false,
};
3 changes: 2 additions & 1 deletion packages/client/src/elements/Swipeout/Swipeout.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface SwipeoutProps {
children: ReactNode;
right: Array<SwipeoutAction>;
onOpen?: () => void;
onSwipe?: () => void;
onSwipeStart?: () => void;
onSwipeEnd?: () => void;
onClose?: () => void;
autoClose?: boolean;
disabled?: boolean;
Expand Down
10 changes: 6 additions & 4 deletions packages/client/src/elements/Swipeout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const Swipeout = ({
autoClose,
right,
onOpen,
onSwipe,
onSwipeStart,
onSwipeEnd,
}: SwipeoutProps) => {
const outerContainerRef = useRef<HTMLDivElement>(null);
const draggableElementRef = useRef(null);
Expand Down Expand Up @@ -59,6 +60,7 @@ const Swipeout = ({

const handleDragStop = useCallback(
(event: DraggableEvent, { x }: DraggableData) => {
onSwipeEnd && onSwipeEnd();
setIsDragging(false);
if (x > 0) {
return;
Expand All @@ -76,13 +78,13 @@ const Swipeout = ({
onOpen && onOpen();
}
},
[actionsContainerWidth, close, isOpen, onOpen],
[actionsContainerWidth, close, isOpen, onOpen, onSwipeEnd],
);

const handleDragStart = useCallback(() => {
setIsDragging(true);
onSwipe && onSwipe();
}, [onSwipe]);
onSwipeStart && onSwipeStart();
}, [onSwipeStart]);

const onActionButtonClick = useCallback(
(onClickCb?: () => void) => () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const RecordRow = styled.div`
`;

export const RecordIconCircle = styled.div<RecordIconCircleProps>(
({ theme: { down, breakpoints }, firstRecord, event }) => css`
({ theme: { palette, down, breakpoints }, firstRecord, event, isSwiping }) => css`
${getRecordIconCircleColors};
border-radius: 100%;
width: ${RECORD_ICON_CIRCLE_SIZE};
Expand All @@ -43,34 +43,42 @@ export const RecordIconCircle = styled.div<RecordIconCircleProps>(
justify-content: center;
align-items: center;
position: relative;
${down(breakpoints.xxs)} {
display: none;
}
${(firstRecord || event === HistoryEvent.TurnedOff) &&
css`
:before {
display: none;
}
`}
`,
);
export const SingleDayRecordsWrapper = styled.div(
({ theme: { palette } }) => css`
display: flex;
flex-direction: column;
${RecordIconCircle}:before {
:before {
content: '';
position: absolute;
top: -${RECORD_ICON_CIRCLE_SIZE};
width: 2px;
height: ${RECORD_ICON_CIRCLE_SIZE};
background: ${palette.primary.dark};
transition: height 300ms ease-in-out;
}
${isSwiping &&
css`
:before {
height: 0;
}
`}
${(firstRecord || event === HistoryEvent.TurnedOff) &&
css`
:before {
display: none;
}
`}
`,
);

export const SingleDayRecordsWrapper = styled.div`
display: flex;
flex-direction: column;
`;

export const TimeLabel = styled.p(
({ theme: { palette } }) => css`
font-weight: 300;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { HistoryEvent } from '../../../enums/historyEvent.enum';
interface RecordIconCircleProps {
event: HistoryEvent;
firstRecord: boolean;
isSwiping: boolean;
}
15 changes: 14 additions & 1 deletion packages/client/src/elements/lists/HistoryCompactList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useFormatDate, useHistoryCompactListData } from '../../../hooks';
Expand All @@ -21,6 +22,10 @@ const HistoryCompactList = () => {
const formatDate = useFormatDate();
const mapHistoryEventToLabel = useHistoryEventLabel(true);
const history = useHistoryCompactListData();
const [swipingRecordIndex, setSwipingRecordIndex] = useState<undefined | number>();

const setSwipingEl = (index: number) => () => setSwipingRecordIndex(index);
const clearSwipingEl = () => setSwipingRecordIndex(undefined);

return (
<ListCard>
Expand All @@ -40,11 +45,19 @@ const HistoryCompactList = () => {
borderRadius: '12px 0 0 12px',
},
]}
onOpen={setSwipingEl(index)}
onSwipeStart={setSwipingEl(index)}
onClose={clearSwipingEl}
onSwipeEnd={clearSwipingEl}
autoClose
>
<RecordRow>
<TimeLabel>{formatDate(createdAt, { timeStyle: 'short' })}</TimeLabel>
<RecordIconCircle event={event} firstRecord={!index}>
<RecordIconCircle
isSwiping={swipingRecordIndex === index || swipingRecordIndex === index - 1}
event={event}
firstRecord={!index}
>
{user ? <StyleOpenLockIcon /> : <StyledPowerSupplyIcon />}
</RecordIconCircle>
<p>{user ? `${user?.firstName} ${user?.lastName}` : t('history.device')}</p>
Expand Down

0 comments on commit 81c39e9

Please sign in to comment.