Skip to content

Extract CrateList component and improve the styling #3349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/components/crate-list.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div ...attributes>
{{!-- The extra div wrapper is needed for specificity issues with `margin` --}}
<ol local-class="list">
{{#if @exactMatch}}
<li local-class="row exact-match">
<LinkTo @route="crate" @model={{@exactMatch}}>
<h1>Exact Match</h1>
</LinkTo>
<CrateRow @crate={{@exactMatch}} data-test-crate-row="exact-match" />
</li>
{{/if}}

{{#each @crates as |crate index|}}
<li local-class="row">
<CrateRow @crate={{crate}} data-test-crate-row={{index}} />
</li>
{{/each}}
</ol>
</div>
20 changes: 20 additions & 0 deletions app/components/crate-list.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.list {
margin: 0;
padding: 0;
list-style: none;
}

.row {
&:not(:last-child) {
margin-bottom: 15px;
}
}

.exact-match:not(:last-child) {
margin-bottom: 60px;

h1 {
margin-top: 0;
color: green
}
}
7 changes: 7 additions & 0 deletions app/components/crate-row.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.crate-row {
--shadow: 0 1px 3px hsla(51, 90%, 42%, .35);

display: flex;
flex-wrap: wrap;
padding: 15px 25px;
background-color: white;
border-radius: 5px;
box-shadow: var(--shadow);
transition: all 300ms;
}

.description-box {
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ export default class SearchController extends Controller {
return yield this.store.query('crate', { all_keywords, page, per_page, q, sort });
}).restartable())
dataTask;

get exactMatch() {
return this.model.find(it => it.exact_match);
}

get otherCrates() {
return this.model.filter(it => !it.exact_match);
}
}
11 changes: 0 additions & 11 deletions app/styles/category/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
11 changes: 0 additions & 11 deletions app/styles/crates.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
border-bottom: 2px solid var(--gray-border);
padding: 20px 0;

&:last-of-type {
border: none;
}
}
11 changes: 0 additions & 11 deletions app/styles/keyword/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
11 changes: 0 additions & 11 deletions app/styles/me/crates.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
11 changes: 0 additions & 11 deletions app/styles/me/following.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
15 changes: 0 additions & 15 deletions app/styles/search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,9 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
}

.exact-match {
margin-bottom: 40px;
border-bottom: solid beige;

h1 {
color: green
}
}

.try-again-button {
composes: yellow-button from './shared/buttons.module.css';
align-self: center;
Expand Down
11 changes: 0 additions & 11 deletions app/styles/team.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
11 changes: 0 additions & 11 deletions app/styles/user.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,5 @@
}

.list {
background-color: white;
padding: 0 20px;
margin-bottom: 20px;
}

.row {
padding: 20px 0;
border-bottom: 2px solid var(--gray-border);

&:last-of-type {
border: none;
}
}
6 changes: 1 addition & 5 deletions app/templates/category/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
6 changes: 1 addition & 5 deletions app/templates/crates.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate index|}}
<CrateRow @crate={{crate}} local-class="row" data-test-crate-row={{index}} />
{{/each}}
</div>
<CrateList @crates={{this.model}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
6 changes: 1 addition & 5 deletions app/templates/keyword/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
6 changes: 1 addition & 5 deletions app/templates/me/crates.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
6 changes: 1 addition & 5 deletions app/templates/me/following.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
17 changes: 1 addition & 16 deletions app/templates/search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,7 @@
</div>
</div>

<div local-class="list">
{{#each this.model as |crate index|}}
{{#if crate.exact_match}}
<div local-class="exact-match">
<LinkTo @route="crate" @model={{crate}}>
<h1>Exact Match</h1>
</LinkTo>
<CrateRow @crate={{crate}} local-class="row" data-test-crate-row={{index}} />
</div>
{{else}}
<div>
<CrateRow @crate={{crate}} local-class="row" data-test-crate-row={{index}} />
</div>
{{/if}}
{{/each}}
</div>
<CrateList @exactMatch={{this.exactMatch}} @crates={{this.otherCrates}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
{{else}}
Expand Down
6 changes: 1 addition & 5 deletions app/templates/team.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model.crates as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model.crates}} local-class="list" />

<Pagination @pagination={{this.pagination}} />
6 changes: 1 addition & 5 deletions app/templates/user.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
</div>
</div>

<div local-class="list">
{{#each this.model.crates as |crate|}}
<CrateRow @crate={{crate}} local-class="row" />
{{/each}}
</div>
<CrateList @crates={{this.model.crates}} local-class="list" />

<Pagination @pagination={{this.pagination}} />