fix mention clientside cache problems

This commit is contained in:
keyan 2023-11-12 14:51:12 -06:00
parent 03acce2305
commit d599ec76ce
2 changed files with 11 additions and 10 deletions

View File

@ -319,7 +319,7 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKe
{...props}
onChange={onChangeInner}
onKeyDown={onKeyDownInner(userSuggestOnKeyDown)}
onBlur={() => setTimeout(resetSuggestions, 100)}
onBlur={() => setTimeout(resetSuggestions, 500)}
onDragEnter={onDragEnter}
onDragLeave={onDragLeave}
onDrop={onDrop}
@ -532,12 +532,12 @@ export function UserSuggest ({
if (q === '') {
getUsers({ variables: { by: 'stacked', when: 'week', limit: 5 } })
} else {
getSuggestions({ variables: { q } })
getSuggestions({ variables: { q, limit: 5 } })
}
} else {
resetSuggestions()
}
}, [query])
}, [query, resetSuggestions, getUsers, getSuggestions])
const onKeyDown = useCallback(e => {
switch (e.code) {
@ -583,6 +583,7 @@ export function UserSuggest ({
break
}
}, [onSelect, resetSuggestions, suggestions])
return (
<>
{children?.({ onKeyDown, resetSuggestions })}

View File

@ -2,14 +2,14 @@ import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client'
import { decodeCursor, LIMIT } from './cursor'
import { SSR } from './constants'
function isFirstPage (cursor, existingThings) {
function isFirstPage (cursor, existingThings, limit = LIMIT) {
if (cursor) {
const decursor = decodeCursor(cursor)
return decursor.offset === LIMIT
return decursor.offset === limit
} else {
// we don't have anything cached, or our existing items are less than
// or equal to a full page
return existingThings?.length < LIMIT
return existingThings?.length < limit
}
}
@ -43,8 +43,8 @@ function getClient (uri) {
},
topUsers: {
keyArgs: ['when', 'by', 'from', 'to', 'limit'],
merge (existing, incoming) {
if (isFirstPage(incoming.cursor, existing?.users)) {
merge (existing, incoming, { args }) {
if (isFirstPage(incoming.cursor, existing?.users, args.limit)) {
return incoming
}
@ -89,8 +89,8 @@ function getClient (uri) {
},
related: {
keyArgs: ['id', 'title', 'minMatch', 'limit'],
merge (existing, incoming) {
if (isFirstPage(incoming.cursor, existing?.items)) {
merge (existing, incoming, { args }) {
if (isFirstPage(incoming.cursor, existing?.items, args.limit)) {
return incoming
}