Skip to content

Commit dc0b238

Browse files
Merge pull request #1115 from Chia-Network/develop
release: 1.2.6 - deeplink for search query
2 parents d9ed597 + 7f3d402 commit dc0b238

File tree

4 files changed

+58
-71
lines changed

4 files changed

+58
-71
lines changed

.github/workflows/deploy-s3.yml

-67
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cadt-ui",
3-
"version": "1.2.5",
3+
"version": "1.2.6",
44
"private": true,
55
"author": "Chia Network Inc. <[email protected]>",
66
"homepage": "./",

src/components/form/SearchInput.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import _ from 'lodash';
2-
import React from 'react';
2+
import React, { useRef, useEffect } from 'react';
33
import { useIntl } from 'react-intl';
44
import { useSelector } from 'react-redux';
55
import styled, { withTheme } from 'styled-components';
6+
import { useQueryParamState } from '../hooks/useQueryParamState';
67

78
import { MagnifyGlassIcon, MagnifyGlassIconWhite } from '../icons';
89

@@ -89,7 +90,10 @@ const ButtonSearchText = styled('p')`
8990
align-items: center;
9091
font-size: 1rem;
9192
width: 3.125rem;
92-
color: ${props => (props.usePrimaryButton ? props.theme.colors.default.onButton : props.theme.colors.default.onSurface)};
93+
color: ${props =>
94+
props.usePrimaryButton
95+
? props.theme.colors.default.onButton
96+
: props.theme.colors.default.onSurface};
9397
box-sizing: border-box;
9498
`;
9599

@@ -104,11 +108,23 @@ const SearchInput = withTheme(
104108
disabled = false,
105109
}) => {
106110
const intl = useIntl();
111+
const ref = useRef();
107112
const appStore = useSelector(state => state.app);
113+
const [searchQuery] = useQueryParamState('search');
114+
115+
useEffect(() => {
116+
onChange({
117+
target: {
118+
value: searchQuery,
119+
},
120+
});
121+
ref.current.value = searchQuery;
122+
}, [searchQuery]);
108123

109124
return (
110125
<SearchContainer usePrimaryButton={usePrimaryButton} size={size}>
111126
<Input
127+
ref={ref}
112128
type="text"
113129
selectedTheme={appStore.theme}
114130
placeholder={intl.formatMessage({ id: 'search' })}
@@ -124,7 +140,8 @@ const SearchInput = withTheme(
124140
selectedTheme={appStore.theme}
125141
usePrimaryButton={usePrimaryButton}
126142
buttonText={buttonText}
127-
disabled={disabled}>
143+
disabled={disabled}
144+
>
128145
{(buttonText && (
129146
<ButtonSearchText usePrimaryButton={usePrimaryButton}>
130147
{buttonText}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import _ from 'lodash';
2+
import { useState, useCallback, useMemo } from 'react';
3+
import { useLocation } from 'react-router-dom';
4+
5+
const useQueryParamState = (name, defaultValue) => {
6+
const [param, setParam] = useState();
7+
const location = useLocation();
8+
9+
const setQueryStringParameter = useCallback(
10+
value => {
11+
const [base, hashFragment] = window.location.hash.split('?');
12+
let params = new URLSearchParams(hashFragment);
13+
14+
if (_.isNil(value) || value === '') {
15+
params.delete(name);
16+
} else {
17+
params.set(name, value);
18+
}
19+
20+
const newHash = params.toString() ? `${base}?${params}` : base;
21+
22+
window.location.hash = decodeURIComponent(newHash);
23+
setParam(value);
24+
},
25+
[name],
26+
);
27+
28+
const value = useMemo(() => {
29+
const [, hashFragment] = window.location.hash.split('?');
30+
const params = new URLSearchParams(hashFragment);
31+
return params.get(name) || defaultValue || '';
32+
}, [location, param, name]);
33+
34+
return [value, setQueryStringParameter];
35+
};
36+
37+
export { useQueryParamState };

0 commit comments

Comments
 (0)