Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/co/bookmarks/export/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function BookmarksExportPopover({ spaceId = 0, pin, onClose }) {

//url generation
const prefix = useMemo(()=>
`${API_ENDPOINT_URL}raindrops/${spaceId}`,
`${API_ENDPOINT_URL}raindrops/${parseInt(spaceId)||0}`,
[spaceId]
)
const suffix = useMemo(()=>
Expand Down
2 changes: 1 addition & 1 deletion src/co/bookmarks/footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function BookmarksFooter({ spaceId, compact, compactLimit }) {
as={Link}
variant='flat'
data-block
to={`/my/${spaceId}/full`}>
to={`/my/${parseInt(spaceId)||0}/full`}>
{t.s('showAll')}
</Button>
)
Expand Down
2 changes: 1 addition & 1 deletion src/co/bookmarks/header/regular/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Icon from '~co/common/icon'
export default ({ className, spaceId })=>(
<Button
className={className}
href={new URL(`/my/${spaceId}`, config.links.app.index).toString()}
href={new URL(`/my/${parseInt(spaceId)||0}`, config.links.app.index).toString()}
target='_blank'
title={t.s('openInNewTab')}>
<Icon name='open' size='micro' />
Expand Down
2 changes: 1 addition & 1 deletion src/co/bookmarks/item/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BookmarksItemTag extends React.PureComponent {
<Link
key={tag}
tabIndex='-1'
to={'/my/'+spaceId+'/'+encodeURIComponent(tag.includes(' ') ? `"#${tag}"` : `#${tag}`)}>
to={'/my/'+(parseInt(spaceId)||0)+'/'+encodeURIComponent(tag.includes(' ') ? `"#${tag}"` : `#${tag}`)}>
<Icon name='tag' size='micro' />
{tag}
</Link>
Expand Down
2 changes: 2 additions & 0 deletions src/co/bookmarks/items/empty/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default class BookmarksEmptyView extends React.PureComponent {
if (spaceId == -101) return null

switch(status.main) {
//case 'loaded' is for "loaded but no bookmarks" situation, no effect if there are bookmarks
case 'loaded':
case 'empty':{
const _id = parseInt(spaceId)

Expand Down
8 changes: 7 additions & 1 deletion src/data/helpers/bookmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ const emptyObject = {}
export * from './blankSpace'
export * from './getUrl'
export * from './queryIsEqual'
export * from './spaceCacheId'
export * from './normalizeRecentSearch'

//Iterator by spaceId prefixes and original
export const iterateSpaceId = (spaceId, func)=>{
export const iterateSpaceId = (spaceId, func, spaces)=>{
const cleanSpaceId = String(parseInt(spaceId))
func(cleanSpaceId)
func(cleanSpaceId+'s')

if (spaces)
for(const id of Object.keys(spaces))
if (id.startsWith(cleanSpaceId+':'))
func(id)
}

//Saga helpers
Expand Down
9 changes: 9 additions & 0 deletions src/data/helpers/bookmarks/spaceCacheId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const FILTER = /^(?:[A-Za-z]+:[A-Za-z]+|❤️)$/

export const getSpaceCacheId = (spaceId, search='')=>{
const filter = String(search).trim()

return String(spaceId) === '0' && FILTER.test(filter) ?
`0:${filter}` :
spaceId
}
14 changes: 8 additions & 6 deletions src/data/reducers/bookmarks/space.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash-es'
import { normalizeBookmarks, blankSpace, queryIsEqual } from '../../helpers/bookmarks'
import { normalizeBookmarks, blankSpace, queryIsEqual, iterateSpaceId } from '../../helpers/bookmarks'
import { actualizeSpaceStatus } from './utils'
import { REHYDRATE } from 'redux-persist/src/constants'
import {
Expand Down Expand Up @@ -340,17 +340,19 @@ export default function(state, action) {switch (action.type) {
.set('meta', state.meta.without(ids))

//remove from *all bookmarks* ids
for(const spaceId of [0, '0s']){
iterateSpaceId(0, (spaceId)=>{
let space = state.spaces[spaceId]
if (!space) continue
if (!space) return

space = space
.set('ids', _.without(space.ids, ...ids))
.set('highlight', space.highlight.without(ids))

state = state.setIn(['spaces', spaceId], space)
}

}, state.spaces)

state = actualizeSpaceStatus(state, 0)

return state
}
}}
8 changes: 6 additions & 2 deletions src/data/reducers/bookmarks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import _ from 'lodash-es'
import { iterateSpaceId } from '../../helpers/bookmarks'

export const actualizeSpaceStatus = (state, spaceId)=>{
const spaces = state.spaces

iterateSpaceId(spaceId, (cleanSpaceId)=>{
const space = state.getIn(['spaces', cleanSpaceId])
var newMainStatus = '',
Expand All @@ -23,7 +25,7 @@ export const actualizeSpaceStatus = (state, spaceId)=>{

if (newNextPageStatus)
state = state.setIn(['spaces', cleanSpaceId, 'status', 'nextPage'], newNextPageStatus)
})
}, spaces)

return state
}
Expand All @@ -42,12 +44,14 @@ export const insertIdToSpace = (state, spaceId, _id)=>{
}

export const removeIdFromSpace = (state, spaceId, _id)=>{
const spaces = state.spaces

iterateSpaceId(spaceId, (cleanSpaceId)=>{
const ids = state.getIn(['spaces', cleanSpaceId, 'ids'])||[]
if (ids.length)
state = state
.setIn(['spaces', cleanSpaceId, 'ids'], ids.filter((id)=>id!=_id))
})
}, spaces)

return state
}
4 changes: 2 additions & 2 deletions src/routes/my/item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Ask from './tab/ask'
import Web from './tab/web'

export default function PageMyItem() {
const { itemId, cId } = useParams()
const { itemId, cId, search } = useParams()
const dispatch = useDispatch()

//webview
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function PageMyItem() {
<Route path='web' element={<Web item={item} webViewRef={webViewRef} />} /> : null
}
{tabs.includes('ask') ?
<Route path='ask' element={<Ask item={item} cId={cId} />} /> : null
<Route path='ask' element={<Ask item={item} cId={cId} search={search} />} /> : null
}

<Route path='*' element={<Any tabs={tabs} />} />
Expand Down
8 changes: 5 additions & 3 deletions src/routes/my/item/tab/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import s from './ask.module.styl'
import React, { useCallback } from 'react'
import { useDispatch } from 'react-redux'
import * as bookmarkActions from '~data/actions/bookmarks'
import useSpaceCacheId from '../../useSpaceCacheId'

import Stella from '~co/stella'

export default function PageMyItemTabAsk({ item, cId }) {
export default function PageMyItemTabAsk({ item, cId, search }) {
const dispatch = useDispatch()
const spaceId = useSpaceCacheId(cId, search)

const onToolCalled = useCallback(() => {
dispatch(bookmarkActions.oneLoad(item._id))
dispatch(bookmarkActions.refresh(cId))
}, [dispatch, item._id, cId])
dispatch(bookmarkActions.refresh(spaceId))
}, [dispatch, item._id, spaceId])

return (
<Stella
Expand Down
5 changes: 4 additions & 1 deletion src/routes/my/space/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import React, { useCallback, useMemo } from 'react'
import { useSelector } from 'react-redux'
import { useNavigate, useLocation } from 'react-router-dom'
import { target, environment, openTab } from '~target'
import useSpaceCacheId from '../useSpaceCacheId'
import Bookmarks from '~co/bookmarks'

export default function PageMySpaceBookmarks({ cId, search, itemId }) {
const { pathname } = useLocation()
let { raindrops_click } = useSelector(state=>state.config)
const navigate = useNavigate()

const spaceId = useSpaceCacheId(cId, search)

const onBookmarkClick = useCallback(item=>{
//no preview in extension, so open in new tab instead
if (target == 'extension' && raindrops_click=='preview')
Expand Down Expand Up @@ -36,7 +39,7 @@ export default function PageMySpaceBookmarks({ cId, search, itemId }) {

return (
<Bookmarks
spaceId={cId}
spaceId={spaceId}
search={search}
full={search || pathname.includes('/full') ? true : false}
activeId={itemId && parseInt(itemId)}
Expand Down
8 changes: 5 additions & 3 deletions src/routes/my/space/header/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import React, { useState, useCallback } from 'react'
import t from '~t'
import { useDispatch, useSelector } from 'react-redux'
import * as bookmarkActions from '~data/actions/bookmarks'
import useSpaceCacheId from '../../useSpaceCacheId'

import Button from '~co/common/button'
import Icon from '~co/common/icon'
import Modal from '~co/overlay/modal'
import Stella from '~co/stella'

export default function PageMySpaceHeaderAsk({ itemId, cId }) {
export default function PageMySpaceHeaderAsk({ itemId, cId, search }) {
const enabled = useSelector(state=>state.config.ai_assistant)
const dispatch = useDispatch()
const spaceId = useSpaceCacheId(cId, search)
const [created, setCreated] = useState(false)
const [visible, setVisible] = useState(false)

Expand All @@ -22,8 +24,8 @@ export default function PageMySpaceHeaderAsk({ itemId, cId }) {
}, [])

const onToolCalled = useCallback(() => {
dispatch(bookmarkActions.refresh(cId))
}, [dispatch, cId])
dispatch(bookmarkActions.refresh(spaceId))
}, [dispatch, spaceId])

const onClose = useCallback(() => {
setVisible(false)
Expand Down
7 changes: 7 additions & 0 deletions src/routes/my/useSpaceCacheId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useMemo } from 'react'
import { getSpaceCacheId } from '~data/helpers/bookmarks'

//use it instead of raw `cId`
export default function useSpaceCacheId(cId, search) {
return useMemo(()=>getSpaceCacheId(cId, search), [cId, search])
}