Skip to content

Commit

Permalink
- Fix double suggest fields request
Browse files Browse the repository at this point in the history
- Fix race of load
- Fix alfred link
  • Loading branch information
exentrich committed Aug 28, 2024
1 parent 3698ac3 commit cbf5bef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 53 deletions.
43 changes: 7 additions & 36 deletions src/co/bookmarks/container/scroll.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,28 @@
import s from './scroll.module.styl'
import _ from 'lodash-es'
import React, { useState, useRef, useCallback, useEffect } from 'react'
import React, { useRef, useCallback } from 'react'
import { useDispatch } from 'react-redux'
import { refresh, nextPage } from '~data/actions/bookmarks'
import { nextPage } from '~data/actions/bookmarks'

export default function BookmarksContainerScroll({ spaceId, children }) {
const div = useRef(null)
const dispatch = useDispatch()

//refresh bookmarks when window is focused and scroll on top
const [dir, setDir] = useState('top')
const actualize = useCallback(
const loadNextPage = useCallback(
_.throttle(()=>{
if (!div.current) return
if (!document.hasFocus()) {
if (dir) setDir('')
if (div.current.scrollTop < div.current.scrollHeight - div.current.offsetHeight*3)
return
}

let newDir = ''

if (div.current.scrollTop >= div.current.scrollHeight - div.current.offsetHeight*3)
newDir = 'bottom'
else if (div.current.scrollTop <= div.current.offsetHeight*2)
newDir = 'top'

if (newDir && dir != newDir){
setDir(dir)

switch(newDir) {
case 'top': dispatch(refresh(spaceId)); break
case 'bottom': dispatch(nextPage(spaceId)); break
}
}
dispatch(nextPage(spaceId))
}, 150),
[div, spaceId, dir, setDir]
[div, spaceId]
)

//react to focused window state
useEffect(()=>{
window.addEventListener('focus', actualize)
window.addEventListener('blur', actualize)
return ()=>{
window.removeEventListener('focus', actualize)
window.removeEventListener('blur', actualize)
}
}, [actualize])

return (
<div
ref={div}
className={s.scroll}
onScroll={actualize}>
onScroll={loadNextPage}>
{children}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/co/bookmarks/edit/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function BookmarkEditForm(props) {
//load suggestions
useEffect(()=>
dispatch(suggestFields(props.item)),
[props.item._id, props.item.media]
[props.item._id]
)

const onSubmitForm = useCallback(e=>{
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/integrations/ready/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function SettingsIntegrationsReady() {

const apps = useMemo(()=>[
{ title: 'Raycast Extension', href: 'https://www.raycast.com/lardissone/raindrop-io' },
{ title: 'Alfred Workflow', href: 'https://www.packal.org/workflow/search-raindropio', icon: 'alfred' }
{ title: 'Alfred Workflow', href: 'https://github.com/westerlind/alfred-raindrop-search', icon: 'alfred' }
], [])

const webs = useMemo(()=>[
Expand Down
36 changes: 21 additions & 15 deletions src/target/extension/background/highlights/highlight.js

Large diffs are not rendered by default.

0 comments on commit cbf5bef

Please sign in to comment.