Skip to content

Commit

Permalink
Show found bookmarks count in title
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustem Mussabekov committed Jun 30, 2024
1 parent 034ff0c commit ee9c9ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/co/bookmarks/header/regular/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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='' },
Expand All @@ -37,34 +28,33 @@ class BookmarksHeaderTitle extends React.Component {
}

render() {
const { isSearching, compact, status, collection: { _id } } = this.props

return (
<>
{isSearching && (
<>
{this.renderSearchStatus()}&nbsp;
{t.s('in')}&nbsp;
</>
)}

{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' ? (
<Link to={`/my/${_id}/full`}>
{this.renderTitle()}
</Link>
) : 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)
2 changes: 2 additions & 0 deletions src/data/selectors/bookmarks/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee9c9ea

Please sign in to comment.