-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reader Manage Following: present a follow button if user appears to have entered a URL #13715
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6deef81
Present a follow button if user appears to have entered a URL
bluefuton 15915c4
Basic styling
bluefuton 95930d4
Prepend protocol for actual follow, and strip for label
bluefuton a370dee
Add following label
bluefuton 49cdb44
Move URL detection into lib/url and reuse existing functions for addi…
bluefuton 5dc0c75
Fix call to addSchemeIfMissing
bluefuton e1aa849
Added some additional test cases
bluefuton 849bf8f
Fix padding
jancavan 86f14aa
Add Follow text in <660px
jancavan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
addSchemeIfMissing, | ||
setUrlScheme, | ||
urlToSlug, | ||
resemblesUrl, | ||
} from '../'; | ||
|
||
describe( 'withoutHttp', () => { | ||
|
@@ -285,3 +286,45 @@ describe( 'urlToSlug()', () => { | |
expect( urlWithoutHttp ).to.equal( 'example.com::example::test123' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'resemblesUrl()', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beautiful. |
||
it( 'should detect a URL', () => { | ||
const source = 'http://example.com/path'; | ||
expect( resemblesUrl( source ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'should detect a URL without protocol', () => { | ||
const source = 'example.com'; | ||
expect( resemblesUrl( source ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'should detect a URL with a query string', () => { | ||
const source = 'http://example.com/path?query=banana&query2=pineapple'; | ||
expect( resemblesUrl( source ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'should detect a URL with a short suffix', () => { | ||
const source = 'http://example.cc'; | ||
expect( resemblesUrl( source ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'should return false with adjacent dots', () => { | ||
const source = '..com'; | ||
expect( resemblesUrl( source ) ).to.equal( false ); | ||
} ); | ||
|
||
it( 'should return false with spaced dots', () => { | ||
const source = '. . .com'; | ||
expect( resemblesUrl( source ) ).to.equal( false ); | ||
} ); | ||
|
||
it( 'should return false with a single dot', () => { | ||
const source = '.'; | ||
expect( resemblesUrl( source ) ).to.equal( false ); | ||
} ); | ||
|
||
it( 'should return false if the string is not a URL', () => { | ||
const source = 'exampledotcom'; | ||
expect( resemblesUrl( source ) ).to.equal( false ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ import FollowingManageSearchFeedsResults from './feed-search-results'; | |
import MobileBackToSidebar from 'components/mobile-back-to-sidebar'; | ||
import { requestFeedSearch } from 'state/reader/feed-searches/actions'; | ||
import { addQueryArgs } from 'lib/url'; | ||
import FollowButton from 'reader/follow-button'; | ||
import { READER_FOLLOWING_MANAGE_URL_INPUT } from 'reader/follow-button/follow-sources'; | ||
import { resemblesUrl, addSchemeIfMissing, withoutHttp } from 'lib/url'; | ||
|
||
class FollowingManage extends Component { | ||
static propTypes = { | ||
|
@@ -94,7 +97,7 @@ class FollowingManage extends Component { | |
this.resizeSearchBox(); | ||
|
||
// this is a total hack. In React-Virtualized you need to tell a WindowScroller when the things | ||
// above it has moved with a call to updatePosision(). Our issue is we don't have a good moment | ||
// above it has moved with a call to updatePosition(). Our issue is we don't have a good moment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't notice this before. thanks for the typo fix :) |
||
// where we know that the content above the WindowScroller has settled down and so instead the solution | ||
// here is to call updatePosition in a regular interval. the call takes about 0.1ms from empirical testing. | ||
this.updatePosition = setInterval( () => { | ||
|
@@ -129,14 +132,20 @@ class FollowingManage extends Component { | |
showMoreResults | ||
} = this.props; | ||
const searchPlaceholderText = translate( 'Search millions of sites' ); | ||
const showExistingSubscriptions = ! ( !! sitesQuery && showMoreResults ); | ||
const isSitesQueryUrl = resemblesUrl( sitesQuery ); | ||
let sitesQueryWithoutProtocol; | ||
if ( isSitesQueryUrl ) { | ||
sitesQueryWithoutProtocol = withoutHttp( sitesQuery ); | ||
} | ||
|
||
return ( | ||
<ReaderMain className="following-manage"> | ||
<DocumentHead title={ 'Manage Following' } /> | ||
<MobileBackToSidebar> | ||
<h1>{ translate( 'Manage Followed Sites' ) }</h1> | ||
</MobileBackToSidebar> | ||
{ ! searchResults && <QueryReaderFeedsSearch query={ sitesQuery } /> } | ||
{ ! searchResults && ! isSitesQueryUrl && <QueryReaderFeedsSearch query={ sitesQuery } /> } | ||
<h2 className="following-manage__header">{ translate( 'Follow Something New' ) }</h2> | ||
<div ref={ this.handleStreamMounted } /> | ||
<div className="following-manage__fixed-area" ref={ this.handleSearchBoxMounted }> | ||
|
@@ -153,8 +162,18 @@ class FollowingManage extends Component { | |
value={ sitesQuery }> | ||
</SearchInput> | ||
</CompactCard> | ||
|
||
{ isSitesQueryUrl && ( | ||
<div className="following-manage__url-follow"> | ||
<FollowButton | ||
followLabel={ translate( 'Follow %s', { args: sitesQueryWithoutProtocol } ) } | ||
followingLabel={ translate( 'Following %s', { args: sitesQueryWithoutProtocol } ) } | ||
siteUrl={ addSchemeIfMissing( sitesQuery, 'http' ) } | ||
followSource={ READER_FOLLOWING_MANAGE_URL_INPUT } /> | ||
</div> | ||
) } | ||
</div> | ||
{ !! sitesQuery && ( | ||
{ !! sitesQuery && ! isSitesQueryUrl && ( | ||
<FollowingManageSearchFeedsResults | ||
searchResults={ searchResults } | ||
showMoreResults={ showMoreResults } | ||
|
@@ -165,7 +184,7 @@ class FollowingManage extends Component { | |
searchResultsCount={ searchResultsCount } | ||
/> | ||
) } | ||
{ ! ( !! sitesQuery && showMoreResults ) && ( | ||
{ showExistingSubscriptions && ( | ||
<FollowingManageSubscriptions | ||
width={ this.state.width } | ||
query={ subsQuery } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may also want to verify that it's a protocol we support or can switch to. For example,
gopher://
would be invalid, but we could switchfeed://
tohttp://
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a cool idea. I won't do it in this particular spot (
resemblesUrl
) because it might be reused by other things, but worth us keeping in mind.