Skip to content

Commit

Permalink
refactor: improve code quality (#129)
Browse files Browse the repository at this point in the history
* refactor: improve code quality

* chore: fix coderefactor issue

* chore: improve ternary operator indentation

* chore: codefactor is kidding

* chore: fix coderefactor issues

* chore: make coderefactor great again

* chore: update listlogo.tsx
  • Loading branch information
Helias authored Nov 12, 2022
1 parent fc92794 commit 9793f36
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/app/contacts/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ const Contact = (props: ContactDetails): JSX.Element => {
<FontAwesomeIcon icon={faEnvelope} />
</Button>{' '}

{props?.linkedin && (<Button href={props.linkedin} target="_blank">
{props?.linkedin
? (<Button href={props.linkedin} target="_blank">
<FontAwesomeIcon icon={faLinkedin} />
</Button>)}
{props?.linkedin && ' '}
</Button>)
: null}
{props?.linkedin ? ' ' : null}

<Button href={`https://github.com/${props.github}`} target="_blank">
<FontAwesomeIcon icon={faGithub} />
Expand Down
6 changes: 4 additions & 2 deletions src/app/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ const Menu: FunctionComponent = () => {
</div>
</div>
</Navbar>
{ showSearch && (
{ showSearch
? (
<Collapse in={showSearch}>
<div className="container-fluid search-form pt-2">
<div className="container">
<SearchForm onClose={(): void => setShowSearch(false)} />
</div>
</div>
</Collapse>
)}
)
: null }
</div>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/results/ListLogo/ListLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ export const ListLogo = (props: Props): JSX.Element => {
return (
<div className="logolist">
{
getListName() !== undefined && getListName() !== 'UNINOMINAL' ? (
getListName() !== undefined && getListName() !== 'UNINOMINAL'
? (
<img key={getListName()}
src={getImageUrl()}
className="logolist m-auto"
onError={(e: any): void => { e.target.onerror = null; e.target.src = 'loghi/image-not-found.svg'; }}
width="80"
height="80"
alt={getListName()} />
) : (
<FontAwesomeIcon icon={faUser} size="4x"></FontAwesomeIcon>
)
: (<FontAwesomeIcon icon={faUser} size="4x"></FontAwesomeIcon>)
}
</div>
);
Expand Down
31 changes: 21 additions & 10 deletions src/app/results/Results/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ResultTable = (props: Props): JSX.Element => {

function getVotiSeggio(votazioni: any): string {
const voti: number = (
seggi && seggi.length > 0
seggi && seggi.length
? seggi.reduce((acc: any, prev: any) => acc + votazioni[`seggio_n_${prev}`], 0)
: votazioni?.totali
);
Expand All @@ -45,13 +45,16 @@ export const ResultTable = (props: Props): JSX.Element => {
lists.map((list: any): JSX.Element =>
<td key={`td-${props.anno}-${i}-${list.nome}`}>
{
candidates[list.nome][i] &&
[
candidates[list.nome][i]
? [
candidates[list.nome][i].nominativo,
(<br key={`${props.anno}-${i}-${list}-${candidates[list.nome][i].nominativo}`} />),
getVotiSeggio(candidates[list.nome][i].voti),
candidates[list.nome][i].eletto && (<Coccarda key={`Coccarda-${list.nome}-${i}`} />)
candidates[list.nome][i].eletto
? (<Coccarda key={`Coccarda-${list.nome}-${i}`} />)
: null
]
: null
}
</td>
)
Expand Down Expand Up @@ -90,7 +93,8 @@ export const ResultTable = (props: Props): JSX.Element => {
(
<th key={`${props.anno}-lista-${list.nome}`}>
{
(props.showDetailsList && seggi && seggi.length > 0) ? (
(props.showDetailsList && seggi && seggi.length)
? (
<OverlayTrigger
placement="bottom"
overlay={detailsListPopover(list)}
Expand All @@ -99,7 +103,8 @@ export const ResultTable = (props: Props): JSX.Element => {
<ListLogo listName={list.nome} />
</div>
</OverlayTrigger>
) : (<ListLogo listName={list.nome} />)
)
: (<ListLogo listName={list.nome} />)
}
<div className="sub-logo" key={`${props.anno}-name-${list.nome}`}>
{list.nome}
Expand All @@ -118,22 +123,28 @@ export const ResultTable = (props: Props): JSX.Element => {
<div className="w-100 bg-light text-dark p-3">
<h4 className="text-primary">{props.anno}</h4>
{
seggi && seggi.length > 0 && <br /> && (
seggi && seggi.length
? (<br /> && (
`Seggi${seggi.length === 1 ? 'o' : ''}: ${seggi.join(', ')
}${!!multiDep && multiDep.length > 1
? ` - ${multiDep.map((d) => d.replaceAll('_', ' ')).join(', ')}`
: ''}`
)
))
: null
}
{
!datareader.hasPassedQuorum(props.anno, props.entity, props.subEntity) && (
!datareader.hasPassedQuorum(props.anno, props.entity, props.subEntity)
? (
<b className="text-danger">[Quorum non raggiunto]</b>
)
: null
}
{
props.anno === '2021-2023' && (
props.anno === '2021-2023'
? (
<b className="text-warning">[Voto online causa pandemia COVID-19]</b>
)
: null
}

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/sub-entity-single/SubEntitySingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function higherPolitics(): JSX.Element | JSX.Element[] {
let hasHighPoliticsSeats = false;

datareader.getYearsOfSubEntity(params.entity, params.subEntity).map((y) => {
if (datareader.getSeatsId(y, params.subEntity) && datareader.getSeatsId(y, params.subEntity).length > 0) {
if (datareader.getSeatsId(y, params.subEntity) && datareader.getSeatsId(y, params.subEntity).length) {
hasHighPoliticsSeats = true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/data/DataReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class DataReader {
getAllCandidates(years: string, entity: string, subEntity: string): any {
const lists: any[] = this.getLists(years, entity, subEntity);
const allCandidates: any = [];
if (lists.length > 0) {
if (lists.length) {
lists.forEach((list: any): any => {
allCandidates[list.nome] = this.getCandidates(years, entity, subEntity, list.nome);
});
Expand Down

0 comments on commit 9793f36

Please sign in to comment.