Skip to content

Commit 9c815c0

Browse files
authored
Add Search input to create pull remote site flow with controlled scroll (#2141)
* Add search input and controlled scroll to create and pull remote site flow
1 parent 1b8d86c commit 9c815c0

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/modules/add-site/components/pull-remote-site.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@wordpress/components';
66
import { check, Icon } from '@wordpress/icons';
77
import { useI18n } from '@wordpress/react-i18n';
8-
import { PropsWithChildren, useEffect } from 'react';
8+
import { PropsWithChildren, useEffect, useState } from 'react';
99
import { ArrowIcon } from 'src/components/arrow-icon';
1010
import Button from 'src/components/button';
1111
import offlineIcon from 'src/components/offline-icon';
@@ -14,7 +14,7 @@ import { useSyncSites } from 'src/hooks/sync-sites';
1414
import { useAuth } from 'src/hooks/use-auth';
1515
import { useOffline } from 'src/hooks/use-offline';
1616
import { getIpcApi } from 'src/lib/get-ipc-api';
17-
import { ListSites } from 'src/modules/sync/components/sync-sites-modal-selector';
17+
import { ListSites, SearchSites } from 'src/modules/sync/components/sync-sites-modal-selector';
1818
import { SyncTabImage } from 'src/modules/sync/components/sync-tab-image';
1919
import type { SyncSite } from 'src/hooks/use-fetch-wpcom-sites/types';
2020

@@ -121,6 +121,15 @@ export function PullRemoteSite( {
121121
const { isAuthenticated } = useAuth();
122122
const { location } = useNavigator();
123123
const { syncSites, refetchSites } = useSyncSites();
124+
const [ searchQuery, setSearchQuery ] = useState< string >( '' );
125+
126+
const filteredSites = syncSites.filter( ( site ) => {
127+
const searchQueryLower = searchQuery.toLowerCase();
128+
return (
129+
site.name?.toLowerCase().includes( searchQueryLower ) ||
130+
site.url?.toLowerCase().includes( searchQueryLower )
131+
);
132+
} );
124133

125134
useEffect( () => {
126135
if ( location.path === '/pullRemote' && isAuthenticated ) {
@@ -138,15 +147,20 @@ export function PullRemoteSite( {
138147
};
139148

140149
return (
141-
<VStack className="text-center w-full" alignment="top" spacing="3">
142-
<Heading className="text-[32px] text-gray-900" weight={ 500 }>
150+
<VStack className="w-full" alignment="top" spacing="3">
151+
<Heading className="text-center text-[32px] text-gray-900" weight={ 500 }>
143152
{ __( 'Pull your remote site' ) }
144153
</Heading>
145-
<ListSites
146-
syncSites={ syncSites }
147-
selectedSiteId={ selectedRemoteSite?.id || null }
148-
onSelectSite={ handleSiteSelect }
149-
/>
154+
<VStack className="flex flex-col w-full max-w-[650px] flex-1">
155+
<SearchSites searchQuery={ searchQuery } setSearchQuery={ setSearchQuery } />
156+
<div className="h-full">
157+
<ListSites
158+
syncSites={ filteredSites }
159+
selectedSiteId={ selectedRemoteSite?.id || null }
160+
onSelectSite={ handleSiteSelect }
161+
/>
162+
</div>
163+
</VStack>
150164
</VStack>
151165
);
152166
}

src/modules/add-site/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function NavigationContent( props: NavigationContentProps ) {
278278
<Navigator.Screen className="flex-1" path="/backup/create">
279279
<CreateSite { ...createSiteProps } />
280280
</Navigator.Screen>
281-
<Navigator.Screen className="flex-1" path="/pullRemote">
281+
<Navigator.Screen className="flex-1 flex justify-center" path="/pullRemote">
282282
<PullRemoteSite
283283
selectedRemoteSite={ selectedRemoteSite }
284284
setSelectedRemoteSite={ ( remoteSite?: SyncSite ) => {

src/modules/sync/components/sync-sites-modal-selector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function SyncSitesModalSelector( {
126126
);
127127
}
128128

129-
function SearchSites( {
129+
export function SearchSites( {
130130
searchQuery,
131131
setSearchQuery,
132132
}: {
@@ -136,9 +136,9 @@ function SearchSites( {
136136
const { __ } = useI18n();
137137
const locale = useI18nLocale();
138138
return (
139-
<div className="flex flex-col px-8 pb-6 border-b border-a8c-gray-5">
139+
<div className="flex flex-col px-8 pb-6 border-b border-a8c-gray-5 shrink-0">
140140
<SearchControl
141-
className="w-full mt-0.5 mb-2"
141+
className="w-full mt-0.5 mb-2 text-black"
142142
placeholder={ __( 'Search sites' ) }
143143
onChange={ ( value ) => {
144144
setSearchQuery( value );

0 commit comments

Comments
 (0)