Skip to content

Commit

Permalink
save around feed aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed May 12, 2017
1 parent 80e56fe commit c4a3406
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions client/state/reader/follows/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,21 @@ export const items = createReducer(
let urlKey = prepareComparableUrl( action.payload.feedUrl );
const newValues = { is_following: true };

const actualFeedUrl = get(
action.payload,
[ 'follow', 'feed_URL' ],
action.payload.feedUrl
);
const actualFeedUrl = get( action.payload, [ 'follow', 'feed_URL' ], action.payload.feedUrl );

const newState = { ...state };
// for the case where a user entered an exact url to follow something, sometimes the
// correct feed_URL is slightly different from what they typed in.
// e.g. example.com --> example.com/rss.
// Since we are keying this reducer by url,
// we need delete the old key and move it to the new one.
// also keep what was typed in as an alias. pretty edge casey but ideally we should retain aliases to
// display correct followByUrl follow button status
if ( actualFeedUrl !== action.payload.feedUrl ) {
newValues.alias_feed_URLs = [
...( state[ urlKey ].alias_feed_URLs || [] ),
prepareComparableUrl( action.payload.feedUrl ),
];
delete newState[ urlKey ];
urlKey = prepareComparableUrl( actualFeedUrl );
} else if ( state[ urlKey ] && state[ urlKey ].error ) {
Expand Down
1 change: 1 addition & 0 deletions client/state/reader/follows/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ describe( 'reducer', () => {
'example.com/feed': {
...subscriptionInfo,
is_following: true,
alias_feed_URLs: [ 'example.com' ],
},
} );
} );
Expand Down
6 changes: 5 additions & 1 deletion client/state/selectors/is-following.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External Dependencies
*/
import { find } from 'lodash';
import { find, includes } from 'lodash';

/**
* Internal Dependencies
Expand All @@ -13,6 +13,10 @@ export default function isFollowing( state, { feedUrl, feedId, blogId } ) {
if ( feedUrl ) {
const url = prepareComparableUrl( feedUrl );
follow = state.reader.follows.items[ url ];
// if follow by url make sure it hasn't been aliased
if ( ! follow ) {
follow = find( state.reader.follows.items, f => includes( f.alias_feed_URLs, url ) );
}
} else if ( feedId ) {
follow = find( state.reader.follows.items, { feed_ID: feedId } );
} else if ( blogId ) {
Expand Down

0 comments on commit c4a3406

Please sign in to comment.