-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add swipe gesture for article cards
- Loading branch information
Showing
9 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ui/src/articles/components/SwipeableArticleCard.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.background { | ||
display: flex; | ||
height: 100%; | ||
background: green; | ||
} | ||
|
||
.background span { | ||
flex: 1 1 auto; | ||
} | ||
|
||
.background i { | ||
font-size: 3em; | ||
align-self: center; | ||
color: white; | ||
padding: 0.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useCallback } from 'react' | ||
import SwipeToDelete from 'react-swipe-to-delete-component' | ||
import 'react-swipe-to-delete-component/dist/swipe-to-delete.css' | ||
|
||
import styles from './SwipeableArticleCard.module.css' | ||
import {Article, UpdateArticleStatusRequest} from '../models' | ||
import ArticleCard from './ArticleCard' | ||
import Icon from '../../common/Icon' | ||
import { useMutation } from 'react-apollo-hooks'; | ||
import { UpdateArticleStatus } from '../queries'; | ||
import { getGQLError } from '../../common/helpers'; | ||
import { IMessageDispatchProps, connectMessageDispatch } from '../../containers/MessageContainer'; | ||
|
||
type Props = { | ||
article: Article | ||
readMoreBasePath: string | ||
} | ||
|
||
type AllProps = Props & IMessageDispatchProps | ||
|
||
const Background = ({icon}: {icon: string}) => ( | ||
<div className={styles.background}> | ||
<Icon name={icon} /> | ||
<span /> | ||
<Icon name={icon} /> | ||
</div> | ||
) | ||
|
||
export const SwipeableArticleCard = (props: AllProps) => { | ||
const {article, readMoreBasePath, showMessage} = props | ||
const updateArticleStatusMutation = useMutation<UpdateArticleStatusRequest>(UpdateArticleStatus) | ||
|
||
const updateArticleStatus = async (status: string) => { | ||
try{ | ||
const res = await updateArticleStatusMutation({ | ||
variables: {id: article.id, status}, | ||
}) | ||
} catch (err) { | ||
showMessage(getGQLError(err), true) | ||
} | ||
} | ||
|
||
const handleOnDelete = useCallback(() => { | ||
const status = article.status === 'read' ? 'unread' : 'read' | ||
updateArticleStatus(status) | ||
}, [article]) | ||
|
||
const bgIcon = article.status === 'read' ? 'undo' : 'done' | ||
|
||
return ( | ||
<SwipeToDelete background={<Background icon={bgIcon} />} onDelete={handleOnDelete}> | ||
<ArticleCard article={article} readMoreBasePath={readMoreBasePath} /> | ||
</SwipeToDelete> | ||
) | ||
} | ||
|
||
export default connectMessageDispatch(SwipeableArticleCard) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
interface Window { | ||
initialReduxState: any | ||
} | ||
} | ||
|
||
declare module 'react-swipe-to-delete-component' |