-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search improvements + better loader #751
base: main
Are you sure you want to change the base?
Conversation
Otherwise the previous limit will be used. E.g. if someone searches for "X" and clicks the "Load more" button three times and the searches for "Y", the limit would be higher then the configuredLimit.
It shows a loading spinner, if more data is loaded for a Data List or Data Column List. I also included "hasMore" in it to trigger a loading for the "Load more" button as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting stuff. As this is purely for aesthetic purposes we must be careful with naming. Simpler is better.
@@ -28,7 +28,15 @@ export const DataBatchContextProvider = connect( | |||
const configuredLimit = dataScope.limit() ?? 20 | |||
const [limit, setLimit] = useState(configuredLimit) | |||
const [initialLimit, setInitialLimit] = useState(configuredLimit) | |||
const [search, setSearch] = useState('') | |||
const [search, setSearchState] = useState('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Unfortunate naming. By not following the useState naming convention we can confuse the reader. Let's please stick to the conventions. How about
[query, setQuery]
?
const setSearch = useCallback( | ||
(query: string) => { | ||
setSearchState(query) | ||
setLimit(configuredLimit) | ||
}, | ||
[configuredLimit], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FYI did you consider resetting the limit as an effect of a query change? Would be more straightforward for a reader, but maybe this causes an issue I'm missing right now.
import { connect, DataScope } from 'scrivito' | ||
import { Loading } from '../../Components/Loading' | ||
|
||
export const CombinedLoader = connect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FYI Naming. A "combined loader" rings no bell even after checking the implementation. Idea: DataBatchLoadingIndicator?
<CombinedLoader | ||
dataScope={dataScope} | ||
hasMore={hasMore} | ||
key={combinedLoaderKey} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FYI Both instances of the Loader use the
DataBatchContext
anduseData()
. How about inlining the props logic instead of duplicating it in the parents?
@@ -2,10 +2,12 @@ import { createContext, useCallback, useState } from 'react' | |||
import { connect, useData, Obj, Widget, ContentTag } from 'scrivito' | |||
|
|||
export const DataBatchContext = createContext<{ | |||
combinedLoaderKey: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Naming: The name looks like it is coupled to a specific purpose which makes it harder to understand if read in isolation. How about
batchKey
?
dataScope: DataScope | ||
hasMore: () => boolean | ||
}) { | ||
// use side-effects to trigger loading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FYI This is misleading. Typically the loading is triggered by the components that show the content. What we do here is something like "to subscribe" to what we assume the components load ,so we can conditionally show the spinner. Or am I reading this wrong?
@@ -43,15 +45,17 @@ export const DataBatchContextProvider = connect( | |||
setLimit(configuredLimit) | |||
} | |||
|
|||
const key = [ | |||
const baseKeys = [ | |||
'DataBatchContextProvider', | |||
content.id(), | |||
attribute, | |||
id, | |||
tag, | |||
search, | |||
// limit is intentionally not included in the key. Otherwise the component would show a loading spinner on every "load more" click. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FYI maybe by using
dataKey
andbatchKey
we could make the code clear enough to go without the comment.
Motivation: When someone clicks on "Load more" a spinner should be shown until all informations are available (more items in the load and the status of "hasMore").
See effect by artificially slowing down
localStorageDataConnection#index
: