Skip to content

Commit 2271c83

Browse files
authored
Reader: Use toggle group control on search page (#102083)
Use `ToggleGroupControl` for sorting on `/reader/search` page which is a core component.
1 parent d7892ac commit 2271c83

File tree

2 files changed

+60
-33
lines changed

2 files changed

+60
-33
lines changed

client/reader/search-stream/index.jsx

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import page from '@automattic/calypso-router';
2-
import { CompactCard, SegmentedControl } from '@automattic/components';
2+
import { CompactCard } from '@automattic/components';
3+
import {
4+
__experimentalToggleGroupControl as ToggleGroupControl,
5+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
6+
} from '@wordpress/components';
37
import clsx from 'clsx';
48
import { localize } from 'i18n-calypso';
59
import { trim, flatMap } from 'lodash';
@@ -88,23 +92,27 @@ class SearchStream extends React.Component {
8892
window.scrollTo( 0, 0 );
8993
};
9094

91-
useRelevanceSort = () => {
92-
const sort = 'relevance';
93-
recordAction( 'search_page_clicked_relevance_sort' );
94-
this.props.recordReaderTracksEvent( 'calypso_reader_clicked_search_sort', {
95-
query: this.props.query,
96-
sort,
97-
} );
98-
updateQueryArg( { sort } );
99-
};
95+
onChangeSortPicker = ( sort ) => {
96+
if ( typeof sort !== 'string' ) {
97+
return;
98+
}
99+
100+
switch ( sort ) {
101+
case 'date':
102+
recordAction( 'search_page_clicked_date_sort' );
103+
break;
104+
case 'relevance':
105+
recordAction( 'search_page_clicked_relevance_sort' );
106+
break;
107+
}
108+
109+
if ( recordReaderTracksEvent ) {
110+
this.props.recordReaderTracksEvent( 'calypso_reader_clicked_search_sort', {
111+
query: this.props.query,
112+
sort,
113+
} );
114+
}
100115

101-
useDateSort = () => {
102-
const sort = 'date';
103-
recordAction( 'search_page_clicked_date_sort' );
104-
this.props.recordReaderTracksEvent( 'calypso_reader_clicked_search_sort', {
105-
query: this.props.query,
106-
sort,
107-
} );
108116
updateQueryArg( { sort } );
109117
};
110118

@@ -121,7 +129,7 @@ class SearchStream extends React.Component {
121129
const { query, translate, searchType, suggestions, isLoggedIn } = this.props;
122130
const sortOrder = this.props.sort;
123131
const wideDisplay = this.props.width > WIDE_DISPLAY_CUTOFF;
124-
const segmentedControlClass = wideDisplay
132+
const toggleGroupControlClasses = wideDisplay
125133
? 'search-stream__sort-picker is-wide'
126134
: 'search-stream__sort-picker';
127135
// Hide posts and sites if the only result has no feed ID. This can happen when searching
@@ -191,17 +199,20 @@ class SearchStream extends React.Component {
191199
</CompactCard>
192200
<SearchFollowButton query={ query } feeds={ this.state.feeds } />
193201
{ query && (
194-
<SegmentedControl compact className={ segmentedControlClass }>
195-
<SegmentedControl.Item
196-
selected={ sortOrder !== 'date' }
197-
onClick={ this.useRelevanceSort }
202+
<div className={ toggleGroupControlClasses }>
203+
<ToggleGroupControl
204+
hideLabelFromVision
205+
isBlock
206+
label=""
207+
value={ sortOrder }
208+
onChange={ this.onChangeSortPicker }
209+
__nextHasNoMarginBottom
210+
__next40pxDefaultSize
198211
>
199-
{ TEXT_RELEVANCE_SORT }
200-
</SegmentedControl.Item>
201-
<SegmentedControl.Item selected={ sortOrder === 'date' } onClick={ this.useDateSort }>
202-
{ TEXT_DATE_SORT }
203-
</SegmentedControl.Item>
204-
</SegmentedControl>
212+
<ToggleGroupControlOption label={ TEXT_RELEVANCE_SORT } value="relevance" />
213+
<ToggleGroupControlOption label={ TEXT_DATE_SORT } value="date" />
214+
</ToggleGroupControl>
215+
</div>
205216
) }
206217
{ ! query && (
207218
<BlankSuggestions

client/reader/search-stream/style.scss

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,29 @@
227227
.search-stream__sort-picker {
228228
position: absolute;
229229
z-index: z-index("root", ".search-stream__sort-picker");
230-
bottom: 15px;
231-
right: 15px;
230+
right: 16px;
231+
top: 100px;
232+
width: 170px;
233+
234+
@include break-small {
235+
right: 0;
236+
}
232237

233238
&.is-wide {
234-
bottom: unset;
235-
right: 50px;
236-
top: 41px;
239+
top: 30px;
240+
right: 45px;
241+
}
242+
}
243+
244+
div.is-section-reader:not(.is-logged-in) {
245+
.search-stream__sort-picker {
246+
top: 64px;
247+
right: 85px;
248+
249+
@include break-small {
250+
top: 76px;
251+
right: 70px;
252+
}
237253
}
238254
}
239255

0 commit comments

Comments
 (0)