From ee9c9ea777ed0630f5105219449131d2dc3384e9 Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Sun, 30 Jun 2024 15:15:28 +0300 Subject: [PATCH] Show found bookmarks count in title --- src/co/bookmarks/header/regular/title.js | 42 +++++++++--------------- src/data/selectors/bookmarks/space.js | 2 ++ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/co/bookmarks/header/regular/title.js b/src/co/bookmarks/header/regular/title.js index f8752ede..ee61be2a 100644 --- a/src/co/bookmarks/header/regular/title.js +++ b/src/co/bookmarks/header/regular/title.js @@ -2,7 +2,7 @@ import React from 'react' import { Link } from 'react-router-dom' import t from '~t' import { connect } from 'react-redux' -import { getSearchEmpty } from '~data/selectors/bookmarks' +import { getSearchEmpty, makeCount } from '~data/selectors/bookmarks' import { makeCollection } from '~data/selectors/collections' class BookmarksHeaderTitle extends React.Component { @@ -11,15 +11,6 @@ class BookmarksHeaderTitle extends React.Component { compact: false, } - renderSearchStatus = ()=>{ - const { status } = this.props - - switch(status.main) { - case 'empty': return t.s('nothingFound') - default: return t.s('defaultCollection-0') - } - } - renderTitle = ()=>{ const { collection: { _id, title='' }, @@ -37,34 +28,33 @@ class BookmarksHeaderTitle extends React.Component { } render() { - const { isSearching, compact, status, collection: { _id } } = this.props - - return ( - <> - {isSearching && ( - <> - {this.renderSearchStatus()}  - {t.s('in')}  - - )} - - {compact && status.main=='loaded' ? ( + const { isSearching, compact, status, collection: { _id }, count } = this.props + + return isSearching ? + ( + status.main == 'loading' ? + '' : + `${count} ${t.s('bookmarks')} ${isSearching ? t.s('found').toLowerCase() : ''}` + ) : + ( + compact && status.main=='loaded' ? ( {this.renderTitle()} - ) : this.renderTitle()} - - ) + ) : this.renderTitle() + ) } } export default connect( () => { const getCollection = makeCollection() + const getCount = makeCount() return (state, { spaceId })=>({ collection: getCollection(state, spaceId), - isSearching: !getSearchEmpty(state, spaceId) + isSearching: !getSearchEmpty(state, spaceId), + count: getCount(state, spaceId), }) } )(BookmarksHeaderTitle) \ No newline at end of file diff --git a/src/data/selectors/bookmarks/space.js b/src/data/selectors/bookmarks/space.js index 712fb0e0..0f392f91 100755 --- a/src/data/selectors/bookmarks/space.js +++ b/src/data/selectors/bookmarks/space.js @@ -23,6 +23,8 @@ export const makeBookmarksLastChange = () => createSelector( export const count = ({bookmarks}, spaceId)=> bookmarks.spaces[spaceId] ? bookmarks.spaces[spaceId].count : blankSpace.count +export const makeCount = ()=>count + //Query export const query = ({bookmarks}, spaceId)=> bookmarks.spaces[spaceId] ? bookmarks.spaces[spaceId].query : blankSpace.query