From a0e15f7bd6d45557bf608e71c8ed98f6b242475e Mon Sep 17 00:00:00 2001 From: "Jeferson S. Brito" <30840709+jeferson-sb@users.noreply.github.com> Date: Mon, 15 Nov 2021 08:06:21 -0300 Subject: [PATCH] Add Snackbar component on reading list (#15235) --- app/javascript/packs/readingList.jsx | 3 +++ app/javascript/readingList/readingList.jsx | 23 ++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/javascript/packs/readingList.jsx b/app/javascript/packs/readingList.jsx index c21d5b8ec..93ff036c8 100644 --- a/app/javascript/packs/readingList.jsx +++ b/app/javascript/packs/readingList.jsx @@ -1,9 +1,12 @@ import { h, render } from 'preact'; + import { ReadingList } from '../readingList/readingList'; +import { Snackbar } from '../Snackbar/Snackbar'; function loadElement() { const root = document.getElementById('reading-list'); if (root) { + render(, document.getElementById('snack-zone')); render( , root, diff --git a/app/javascript/readingList/readingList.jsx b/app/javascript/readingList/readingList.jsx index 6f63c075e..66c892991 100644 --- a/app/javascript/readingList/readingList.jsx +++ b/app/javascript/readingList/readingList.jsx @@ -9,6 +9,7 @@ import { selectTag, clearSelectedTags, } from '../searchableItemList/searchableItemList'; +import { addSnackbarItem } from '../Snackbar'; import { ItemListItem } from './components/ItemListItem'; import { ItemListItemArchiveButton } from './components/ItemListItemArchiveButton'; import { TagList } from './components/TagList'; @@ -44,7 +45,6 @@ export class ReadingList extends Component { const { statusView } = this.props; this.state = { - archiving: false, query: '', index: null, page: 0, @@ -107,6 +107,8 @@ export class ReadingList extends Component { event.preventDefault(); const { statusView, items, itemsTotal } = this.state; + const isStatusViewValid = this.statusViewValid(); + request(`/reading_list_items/${item.id}`, { method: 'PUT', body: { current_status: statusView }, @@ -115,15 +117,13 @@ export class ReadingList extends Component { const newItems = items; newItems.splice(newItems.indexOf(item), 1); this.setState({ - archiving: true, items: newItems, itemsTotal: itemsTotal - 1, }); - // hide the snackbar in a few moments - setTimeout(() => { - this.setState({ archiving: false }); - }, 1000); + addSnackbarItem({ + message: isStatusViewValid ? 'Archiving...' : 'Unarchiving...', + }); }; statusViewValid() { @@ -180,22 +180,12 @@ export class ReadingList extends Component { availableTags, selectedTag = '', showLoadMoreButton, - archiving, loading = false, } = this.state; const isStatusViewValid = this.statusViewValid(); const archiveButtonLabel = isStatusViewValid ? 'Archive' : 'Unarchive'; - const snackBar = archiving ? ( -
-
- {isStatusViewValid ? 'Archiving...' : 'Unarchiving...'} -
-
- ) : ( - '' - ); return (
- {snackBar}
); }