Skip to content

Commit

Permalink
Improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustem Mussabekov committed May 17, 2024
1 parent 392f345 commit 15f74bc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/co/bookmarks/edit/form/collection/suggested.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { isPro } from '~data/selectors/user'

import Button from '~co/common/button'

const self = { self: true }

function Suggestion({ id, onClick }) {
const getCollectionPath = useMemo(()=>makeCollectionPath(), [])
const path = useSelector(state=>getCollectionPath(state, id, { self: true }))
const path = useSelector(state=>getCollectionPath(state, id, self))
const shortPath = useMemo(()=>path.map((p)=>p.title).slice(-2).join(' / '), [path])
const fullPath = useMemo(()=>path.map((p)=>p.title).join(' / '), [path])
const collection = useMemo(()=>path?.[path.length-1], [path])
Expand Down
3 changes: 1 addition & 2 deletions src/co/bookmarks/edit/form/tags/suggested.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default function BookmarkEditFormTagsSuggested({ item, onTagClick }) {
const enabled = useSelector(state=>state.config.ai_suggestions)
const pro = useSelector(state=>isPro(state))
const getSuggestedFields = useMemo(()=>makeSuggestedFields(), [])
const suggestions = useSelector(state=>getSuggestedFields(state, item))
const tags = useMemo(()=>(suggestions.tags||[]).filter(tag=>!item.tags.includes(tag)), [suggestions.tags, item.tags])
const { tags=[] } = useSelector(state=>getSuggestedFields(state, item))

//click
const onSuggestionClick = useCallback(e=>{
Expand Down
2 changes: 1 addition & 1 deletion src/data/reducers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const initialState = Immutable({

acknowledge: [],

ai_suggestions: false
ai_suggestions: true
})

//this keys can be kept untouched on reset
Expand Down
2 changes: 1 addition & 1 deletion src/data/sagas/bookmarks/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function* reorder({ _id, ignore, order, collectionId }) {

function* suggestFields({ obj, ignore }) {
if (ignore) return;
if (!obj?.link) return;
if (!obj?.link && !obj?._id) return;

try{
const { item } = obj._id ?
Expand Down
22 changes: 13 additions & 9 deletions src/data/selectors/bookmarks/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ export const makeCreatorRef = ()=>createSelector(
export const makeSuggestedFields = ()=>createSelector(
[
({bookmarks}, { link })=>bookmarks.suggestedFields[link] || {},
(_, { collectionId })=>collectionId
(_, { collectionId })=>collectionId,
(_, { tags })=>tags
],
({ collections=[], tags=[] }, collectionId)=>({
collections: collections?.[0] == collectionId ?
emptyArray :
[...collections]
.filter(cid=>cid!=collectionId)
.splice(0, 5),
tags
})
({ collections=[], tags=[] }, collectionId, itemTags)=>{
return ({
collections: collections?.[0] == collectionId ?
emptyArray :
[...collections]
.filter(cid=>cid!=collectionId)
.splice(0, 5),
tags: tags
.filter(tag=>!itemTags?.includes(tag))
})
}
)

0 comments on commit 15f74bc

Please sign in to comment.