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

View File

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