Skip to content

Commit

Permalink
Merge pull request #1115 from Chia-Network/develop
Browse files Browse the repository at this point in the history
release: 1.2.6 - deeplink for search query
  • Loading branch information
TheLastCicada authored Oct 4, 2023
2 parents d9ed597 + 7f3d402 commit dc0b238
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 71 deletions.
67 changes: 0 additions & 67 deletions .github/workflows/deploy-s3.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt-ui",
"version": "1.2.5",
"version": "1.2.6",
"private": true,
"author": "Chia Network Inc. <[email protected]>",
"homepage": "./",
Expand Down
23 changes: 20 additions & 3 deletions src/components/form/SearchInput.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import _ from 'lodash';
import React from 'react';
import React, { useRef, useEffect } from 'react';
import { useIntl } from 'react-intl';
import { useSelector } from 'react-redux';
import styled, { withTheme } from 'styled-components';
import { useQueryParamState } from '../hooks/useQueryParamState';

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

Expand Down Expand Up @@ -89,7 +90,10 @@ const ButtonSearchText = styled('p')`
align-items: center;
font-size: 1rem;
width: 3.125rem;
color: ${props => (props.usePrimaryButton ? props.theme.colors.default.onButton : props.theme.colors.default.onSurface)};
color: ${props =>
props.usePrimaryButton
? props.theme.colors.default.onButton
: props.theme.colors.default.onSurface};
box-sizing: border-box;
`;

Expand All @@ -104,11 +108,23 @@ const SearchInput = withTheme(
disabled = false,
}) => {
const intl = useIntl();
const ref = useRef();
const appStore = useSelector(state => state.app);
const [searchQuery] = useQueryParamState('search');

useEffect(() => {
onChange({
target: {
value: searchQuery,
},
});
ref.current.value = searchQuery;
}, [searchQuery]);

return (
<SearchContainer usePrimaryButton={usePrimaryButton} size={size}>
<Input
ref={ref}
type="text"
selectedTheme={appStore.theme}
placeholder={intl.formatMessage({ id: 'search' })}
Expand All @@ -124,7 +140,8 @@ const SearchInput = withTheme(
selectedTheme={appStore.theme}
usePrimaryButton={usePrimaryButton}
buttonText={buttonText}
disabled={disabled}>
disabled={disabled}
>
{(buttonText && (
<ButtonSearchText usePrimaryButton={usePrimaryButton}>
{buttonText}
Expand Down
37 changes: 37 additions & 0 deletions src/components/hooks/useQueryParamState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import _ from 'lodash';
import { useState, useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';

const useQueryParamState = (name, defaultValue) => {
const [param, setParam] = useState();
const location = useLocation();

const setQueryStringParameter = useCallback(
value => {
const [base, hashFragment] = window.location.hash.split('?');
let params = new URLSearchParams(hashFragment);

if (_.isNil(value) || value === '') {
params.delete(name);
} else {
params.set(name, value);
}

const newHash = params.toString() ? `${base}?${params}` : base;

window.location.hash = decodeURIComponent(newHash);
setParam(value);
},
[name],
);

const value = useMemo(() => {
const [, hashFragment] = window.location.hash.split('?');
const params = new URLSearchParams(hashFragment);
return params.get(name) || defaultValue || '';
}, [location, param, name]);

return [value, setQueryStringParameter];
};

export { useQueryParamState };

0 comments on commit dc0b238

Please sign in to comment.