Skip to content

Instantly share code, notes, and snippets.

@skayred
Created June 23, 2017 15:23
Show Gist options
  • Save skayred/e2454b16c255f6f06668c8b3a71272bf to your computer and use it in GitHub Desktop.
Save skayred/e2454b16c255f6f06668c8b3a71272bf to your computer and use it in GitHub Desktop.
const createCategorizedList = (routeCategory?: string) => {
return asyncConnect(
[{
promise: (props: AsyncProps) => {
const page = props.location.query.page || 1;
const ordering = props.location.query.ordering || '-date_publish';
const tag = props.location.query.tag || '';
const category = routeCategory ? routeCategory : categoryFromProps(props);
const params = { page, ordering, tag, category };
const requests = [
{
type: 'stati',
request: getArticles(params),
},
];
return selectedRequest(requests, props);
},
},
{
promise: (props: AsyncProps) => {
const category = routeCategory ? routeCategory : categoryFromProps(props);
const tag = props.location.query.tag;
const crumbs: IBreadItem[] = [
{ path: '/magazine' },
{ path: '/stati' },
];
if (!!tag) {
const name = tag[0].toUpperCase() + tag.substr(1);
crumbs.push({
path: tag,
url: `/stati?tag=${tag}`,
name,
});
} else if (!!category) {
crumbs.push({ path: category });
}
return props.store.dispatch(setBreadCrumb(crumbs));
},
},
{
promise: (props: AsyncProps) => props.store.dispatch(getDiscussed()),
}],
)(ArticlesConnected);
}
export const Articles = createCategorizedList();
export const InterviewArticles = createCategorizedList('interview');
export const ReviewArticles = createCategorizedList('review');
export const AnalyticsArticles = createCategorizedList('analytics');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment