nitro-web 0.3.17 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -56,6 +56,13 @@ export function Filters({
|
|
|
56
56
|
const [state, setState] = [stateProp || stateDefault, setStateProp || setStateDefault]
|
|
57
57
|
const count = useMemo(() => Object.keys(state).filter((k) => state[k] && filters?.some((f) => f.name === k)).length, [state, filters])
|
|
58
58
|
const pushChangesToPath = usePushChangesToPath(state)
|
|
59
|
+
const flushRef = useRef(false)
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// Only typing is debounced, everything else flushes here (not in the handler, the new state is only available after render)
|
|
63
|
+
if (flushRef.current) pushChangesToPath.flush()
|
|
64
|
+
flushRef.current = false
|
|
65
|
+
}, [state])
|
|
59
66
|
|
|
60
67
|
const Elements = {
|
|
61
68
|
Button: elements?.Button || Button,
|
|
@@ -84,16 +91,17 @@ export function Filters({
|
|
|
84
91
|
onAfterChange()
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
async function onInputChange(e: {target: {name: string, value: unknown}}) {
|
|
94
|
+
async function onInputChange(e: {target: {name: string, value: unknown}}, isTyping: boolean) {
|
|
88
95
|
// console.log('onInputChange', e.target.name, e.target.value)
|
|
89
96
|
// the state is flattened for the query string, so here we se full paths as the key names e.g. 'job.location': '10')
|
|
90
97
|
setState((s) => ({ ...s, [e.target.name]: e.target.value as unknown }))
|
|
91
|
-
onAfterChange()
|
|
98
|
+
onAfterChange(isTyping)
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
function onAfterChange() {
|
|
101
|
+
function onAfterChange(isTyping = false) {
|
|
95
102
|
setLastUpdated(Date.now())
|
|
96
103
|
pushChangesToPath()
|
|
104
|
+
flushRef.current = !isTyping
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
function getBasisWidth(width: 'full' | 'half' | 'third' | 'quarter' | 'fifth') {
|
|
@@ -160,7 +168,7 @@ export function Filters({
|
|
|
160
168
|
{
|
|
161
169
|
filters?.map(({label, width='full', rowClassName, ...filter}, i) => {
|
|
162
170
|
// `filter.name` is a full path e.g. 'job.location', not just the key `location`
|
|
163
|
-
const common = { className: '!mb-0', onChange: onInputChange
|
|
171
|
+
const common = { className: '!mb-0', onChange: (e: {target: {name: string, value: unknown}}) => onInputChange(e, filter.type !== 'select') }
|
|
164
172
|
return (
|
|
165
173
|
<div key={i} class={twMerge(getBasisWidth(width), rowClassName || '')}>
|
|
166
174
|
<div class="flex justify-between">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|