Skip to content

Commit

Permalink
Renamed type to topic
Browse files Browse the repository at this point in the history
  • Loading branch information
nimzco authored and Nima Izadi committed Mar 5, 2018
1 parent a986421 commit 79b9af3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default function App() {
<Head />
<div>
<Switch>
<Route path="/cfp/:type/:country" render={renderCFP} />
<Route path="/cfp/:type/" render={renderCFP} />
<Route path="/cfp/:topic/:country" render={renderCFP} />
<Route path="/cfp/:topic/" render={renderCFP} />
<Route path="/cfp" render={renderCFP} />
<Route path="/:year/:type/:country" render={redirect} />
<Route path="/:type/:country" render={redirectOrRender} />
<Route path="/:type" component={ConferencePage} />
<Route path="/:year/:topic/:country" render={redirect} />
<Route path="/:topic/:country" render={redirectOrRender} />
<Route path="/:topic" component={ConferencePage} />
<Route exact path="/" component={ConferencePage} />
<Route component={ConferencePage} />
</Switch>
Expand All @@ -29,30 +29,30 @@ function renderCFP({match}) {
}

function redirect(props) {
const {type, country} = props.match.params;
const {topic, country} = props.match.params;

return <Redirect to={`/${type}/${country}`} state={{status: 301}} />;
return <Redirect to={`/${topic}/${country}`} state={{status: 301}} />;
}

/*
Old routes were /:year/:type and now is /:type/:country
If we detect that :type is a year, the user actually wanted to reach
the new route /:type
Old routes were /:year/:topic and now is /:topic/:country
If we detect that :topic is a year, the user actually wanted to reach
the new route /:topic
*/
function redirectOrRender(props) {
const {type, country} = props.match.params;
const {topic, country} = props.match.params;

if (isYear(type)) {
if (isYear(topic)) {
return <Redirect to={`/${country}`} state={{status: 301}} />;
} else {
return <ConferencePage {...props} fallback={redirectToType} />;
return <ConferencePage {...props} fallback={redirectToTopic} />;
}
}

function isYear(year) {
return (year.length === 4 && !isNaN(parseInt(year, 10)));
}

function redirectToType(type) {
return <Redirect to={`/${type}`} state={{status: 301}} />;
function redirectToTopic(topic) {
return <Redirect to={`/${topic}`} state={{status: 301}} />;
}
10 changes: 5 additions & 5 deletions src/components/ConferencePage/ConferencePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ class ConferencePage extends Component {

render() {
const {showPast, sortBy} = this.state;
const {showCFP, match: {params: {type, country}}} = this.props;
const addConferenceUrl = getAddConferenceUrl(type);
const {showCFP, match: {params: {topic, country}}} = this.props;
const addConferenceUrl = getAddConferenceUrl(topic);

return (
<div>
<Helmet>
<title>Tech conferences | Confs.tech</title>
</Helmet>
<Favicon url={`/${type}.png`} />
<Favicon url={`/${topic}.png`} />
<header className={styles.Header}>
<h1 className="visuallyHidden">
List of all {type ? TOPICS[type] : 'tech'} conferences of {CURRENT_YEAR}
List of all {topic ? TOPICS[topic] : 'tech'} conferences of {CURRENT_YEAR}
{country ? ` in ${country}` : null}
</h1>
<Heading element="p">Find your next tech conference</Heading>
Expand All @@ -103,7 +103,7 @@ class ConferencePage extends Component {
/>
<RefinementList
attributeName="topics"
defaultRefinement={type ? [type] : []}
defaultRefinement={topic ? [topic] : []}
transformItems={transformTopicRefinements}
/>
<RefinementList
Expand Down
4 changes: 2 additions & 2 deletions src/components/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ const REPO_URLS = {
general: 'https://github.com/tech-conferences/confs.tech',
};

export function getAddConferenceUrl(type = 'JavaScript') {
return `${REPO_URLS[type.toLocaleLowerCase()]}/issues/new`;
export function getAddConferenceUrl(topic = 'JavaScript') {
return `${REPO_URLS[topic.toLocaleLowerCase()]}/issues/new`;
}

0 comments on commit 79b9af3

Please # to comment.