Skip to content

Commit 9661fe2

Browse files
committed
Toggles yank/unyank button
1 parent c1d623d commit 9661fe2

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

app/controllers/crate/version.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,8 @@ export default Controller.extend({
156156
yankVersionTask: task(function* (version) {
157157
return version.yank.perform();
158158
}),
159+
160+
unyankVersionTask: task(function* (version) {
161+
return version.unyank.perform();
162+
}),
159163
});

app/models/version.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ export default class Version extends Model {
7070
return yield response.text();
7171
}).keepLatest())
7272
yank;
73+
74+
@(task(function* () {
75+
let response = yield fetch(`/api/v1/crates/${this.crate.id}/${this.num}/unyank`, { method: 'PUT' });
76+
if (!response.ok) {
77+
throw new Error(`Yank request for ${this.crateName} v${this.num} failed`);
78+
}
79+
80+
return yield response.text();
81+
}).keepLatest())
82+
unyank;
7383
}

app/templates/crate/version.hbs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@
168168
{{ version.num }}
169169
</LinkTo>
170170
{{moment-format version.created_at 'll'}}
171-
{{#if version.yanked}}
172-
<span local-class='yanked'>yanked</span>
173-
{{/if}}
174171
{{#if isOwner}}
175-
<button type="button" local-class="remove-button" {{on "click" (perform this.yankVersionTask version)}}>Yank</button>
172+
{{#if version.yanked}}
173+
<button type="button" local-class="remove-button" {{on "click" (perform this.unyankVersionTask version)}}>Unyank</button>
174+
{{else}}
175+
<button type="button" local-class="remove-button" {{on "click" (perform this.yankVersionTask version)}}>Yank</button>
176+
{{/if}}
177+
{{else}}
178+
{{#if version.yanked}}
179+
<span local-class='yanked'>yanked</span>
180+
{{/if}}
176181
{{/if}}
177182
</li>
178183
{{/each}}

0 commit comments

Comments
 (0)