Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
style(Navigation): implement switch cases for code reduction - I91
Browse files Browse the repository at this point in the history
Signed-off-by: irmerk <[email protected]>
  • Loading branch information
jolanglinais committed Aug 15, 2019
1 parent 3ab0de7 commit 402e946
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
23 changes: 12 additions & 11 deletions src/Navigation/actions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export const isClause = input => input === 'clause';
export const isHeadingOne = input => input === 'heading_one';
export const isHeadingTwo = input => input === 'heading_two';
export const isHeadingThree = input => input === 'heading_three';

const truncateHeading = (heading, length) => ((heading.length > length)
? `${heading.substring(0, length)}...`
: heading);


export const truncateHeader = ({ type, text }) => {
if (isClause(type)) return truncateHeading(text, 20);
if (isHeadingOne(type)) return truncateHeading(text, 22);
if (isHeadingTwo(type)) return truncateHeading(text, 18);
if (isHeadingThree(type)) return truncateHeading(text, 14);
return 'Error!';
switch (type) {
case 'clause':
return truncateHeading(text, 20);
case 'heading_one':
return truncateHeading(text, 22);
case 'heading_two':
return truncateHeading(text, 18);
case 'heading_three':
return truncateHeading(text, 14);
default:
return 'Error!';
}
};
41 changes: 20 additions & 21 deletions src/Navigation/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';

/* Actions */
import * as ACT from './actions';
import { truncateHeader } from './actions';

/* Styling */
import * as SC from './styles';
Expand All @@ -18,50 +18,49 @@ export const headerGenerator = (props) => {

return headers.map((header) => {
const { type, key } = header;
if (ACT.isClause(type)) {
return (
switch (type) {
case 'clause':
return (
<SC.HeaderClause
key={key}
onClick={() => navigateHeader(key, type)}
{...props.styleProps}
>
{ACT.truncateHeader(header)}
{truncateHeader(header)}
</ SC.HeaderClause>
);
}
if (ACT.isHeadingOne(type)) {
return (
);
case 'heading_one':
return (
<SC.HeaderOne
key={key}
onClick={() => navigateHeader(key, type)}
{...props.styleProps}
>
{ACT.truncateHeader(header)}
{truncateHeader(header)}
</ SC.HeaderOne>
);
}
if (ACT.isHeadingTwo(type)) {
return (
);
case 'heading_two':
return (
<SC.HeaderTwo
key={key}
onClick={() => navigateHeader(key, type)}
{...props.styleProps}
>
{ACT.truncateHeader(header)}
{truncateHeader(header)}
</ SC.HeaderTwo>
);
}
if (ACT.isHeadingThree(type)) {
return (
);
case 'heading_three':
return (
<SC.HeaderThree
key={key}
onClick={() => navigateHeader(key, type)}
{...props.styleProps}
>
{ACT.truncateHeader(header)}
{truncateHeader(header)}
</ SC.HeaderThree>
);
);
default:
return 'Error!';
}
return 'Error!';
});
};

0 comments on commit 402e946

Please sign in to comment.