Skip to content

Commit 12b92d8

Browse files
committed
Auto merge of #3251 - Turbo87:version-list, r=locks
Extract and improve `VersionList::Row` component ### Before <img width="573" alt="Bildschirmfoto 2021-02-07 um 19 26 01" src="https://user-images.githubusercontent.com/141300/107155751-6ec0fc80-697a-11eb-8d4b-4300ee287741.png"> ### After <img width="570" alt="Bildschirmfoto 2021-02-07 um 19 25 45" src="https://user-images.githubusercontent.com/141300/107155753-72ed1a00-697a-11eb-849a-f6f4d27ee337.png">
2 parents 30e3760 + 80a7edd commit 12b92d8

File tree

7 files changed

+94
-57
lines changed

7 files changed

+94
-57
lines changed

app/components/version-list/row.hbs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div local-class="row" ...attributes>
2+
<div>
3+
<LinkTo
4+
@route="crate.version"
5+
@model={{@version.num}}
6+
local-class="num-link"
7+
>
8+
{{@version.num}}
9+
</LinkTo>
10+
11+
{{#if @version.yanked}}
12+
<span local-class='yanked'>yanked</span>
13+
{{/if}}
14+
</div>
15+
16+
<span title={{date-format @version.created_at 'PPP'}} local-class="date">
17+
{{date-format-distance-to-now @version.created_at addSuffix=true}}
18+
</span>
19+
20+
{{#if this.isOwner}}
21+
<YankButton @version={{@version}} local-class="yank-button" />
22+
{{/if}}
23+
</div>

app/components/version-list/row.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { computed } from '@ember/object';
2+
import { inject as service } from '@ember/service';
3+
import Component from '@glimmer/component';
4+
5+
export default class VersionRow extends Component {
6+
@service session;
7+
8+
@computed('args.version.crate.owner_user', 'session.currentUser.id')
9+
get isOwner() {
10+
return this.args.version.crate?.owner_user?.findBy('id', this.session.currentUser?.id);
11+
}
12+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.row {
2+
display: flex;
3+
align-items: center;
4+
position: relative;
5+
padding: 20px;
6+
transition: background-color 300ms;
7+
8+
&:hover {
9+
background-color: var(--grey200);
10+
transition: background-color 0ms;
11+
}
12+
13+
& >:first-child {
14+
flex-grow: 1;
15+
}
16+
}
17+
18+
.num-link {
19+
font-variant-numeric: tabular-nums;
20+
21+
&::after {
22+
content: '';
23+
position: absolute;
24+
left: 0;
25+
top: 0;
26+
right: 0;
27+
bottom: 0;
28+
}
29+
}
30+
31+
.date {
32+
composes: small from '../../styles/shared/typography.module.css';
33+
display: inline-block;
34+
margin-left: 20px;
35+
position: relative;
36+
}
37+
38+
.yanked {
39+
composes: yanked from '../../styles/shared/typography.module.css';
40+
}
41+
42+
.yank-button {
43+
position: relative;
44+
margin-left: 10px;
45+
}

app/controllers/crate/versions.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/styles/application.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:root {
22
--violet800: hsl(252, 44%, 24%);
33
--grey900: hsl(200, 15%, 19%);
4+
--grey200: hsl(200, 17%, 96%);
45
--green800: hsl(115, 31%, 31%);
56
--yellow500: hsl(44, 100%, 60%);
67

app/styles/crate/versions.module.css

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,17 @@
1010
margin-top: 10px;
1111
padding: 0 20px;
1212
background-color: white;
13-
}
13+
list-style: none;
1414

15-
.row {
16-
display: flex;
17-
justify-content: space-between;
18-
flex-wrap: wrap;
19-
padding: 20px 0;
20-
border-bottom: 2px solid #d5d3cb;
15+
> li {
16+
border-bottom: 2px solid #d5d3cb;
2117

22-
&:last-of-type {
23-
border: none;
18+
&:last-of-type {
19+
border: none;
20+
}
2421
}
2522
}
2623

27-
.date {
28-
composes: small from '../shared/typography.module.css';
29-
display: inline-block;
30-
margin-left: 20px;
31-
}
32-
33-
.yanked {
34-
composes: yanked from '../shared/typography.module.css';
35-
}
36-
37-
.arrow {
38-
display: inline-block;
39-
float: right;
40-
41-
svg {
42-
background: #EEECDD;
43-
}
24+
.row {
25+
margin: 0 -20px;
4426
}

app/templates/crate/versions.hbs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,10 @@
88
{{date-format this.model.created_at 'PPP'}}
99
</span>
1010

11-
<div local-class="list">
11+
<ul local-class="list">
1212
{{#each this.model.versions as |version|}}
13-
<div local-class="row">
14-
<div>
15-
<LinkTo @route="crate.version" @model={{version.num}}>{{ version.num }}</LinkTo>
16-
17-
<span local-class="date">{{date-format version.created_at 'PPP'}}</span>
18-
{{#if version.yanked}}
19-
<span local-class='yanked'>yanked</span>
20-
{{/if}}
21-
</div>
22-
{{#if this.isOwner}}
23-
<YankButton @version={{version}} />
24-
{{else}}
25-
<LinkTo @route="crate.version" @model={{version.num}} local-class="arrow">
26-
{{svg-jar "right-arrow"}}
27-
</LinkTo>
28-
{{/if}}
29-
</div>
13+
<li>
14+
<VersionList::Row @version={{version}} local-class="row" />
15+
</li>
3016
{{/each}}
31-
</div>
17+
</ul>

0 commit comments

Comments
 (0)