Skip to content

Commit 2814896

Browse files
committed
combined JS and HBS
2 parents ecc73f9 + 11176fd commit 2814896

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1127
-1101
lines changed

app/components/color-scheme-menu.gjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
export default class Header extends Component {
5+
/** @type {import("../services/dark-mode").default} */
6+
@service colorScheme;
7+
8+
colorSchemes = [
9+
{ mode: 'light', svg: 'sun' },
10+
{ mode: 'dark', svg: 'moon' },
11+
{ mode: 'system', svg: 'color-mode' },
12+
];
13+
14+
get icon() {
15+
return this.colorSchemes.find(({ mode }) => mode === this.colorScheme.scheme)?.svg;
16+
}
17+
}
18+
119
<Dropdown data-test-dark-mode-menu ...attributes class="dropdown" as |dd|>
220
<dd.Trigger @hideArrow={{true}} class="trigger" data-test-dark-mode-toggle>
321
{{svg-jar this.icon class=(scoped-class "icon")}}

app/components/color-scheme-menu.js

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

app/components/copy-button.gjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
import { restartableTask } from 'ember-concurrency';
5+
6+
export default class CrateTomlCopy extends Component {
7+
@service notifications;
8+
9+
copyTask = restartableTask(async () => {
10+
let { copyText } = this.args;
11+
try {
12+
await navigator.clipboard.writeText(copyText);
13+
this.notifications.success('Copied to clipboard!');
14+
} catch {
15+
this.notifications.error('Copy to clipboard failed!');
16+
}
17+
});
18+
}
19+
120
<button type="button" ...attributes {{on "click" (perform this.copyTask)}}>
221
{{yield}}
322
</button>

app/components/copy-button.js

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

app/components/crate-header.gjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
import { task } from 'ember-concurrency';
5+
import { alias } from 'macro-decorators';
6+
7+
export default class CrateHeader extends Component {
8+
@service session;
9+
10+
@alias('loadKeywordsTask.last.value') keywords;
11+
12+
constructor() {
13+
super(...arguments);
14+
15+
this.loadKeywordsTask.perform().catch(() => {
16+
// ignore all errors and just don't display keywords if the request fails
17+
});
18+
}
19+
20+
get isOwner() {
21+
let userId = this.session.currentUser?.id;
22+
return this.args.crate?.hasOwnerUser(userId) ?? false;
23+
}
24+
25+
loadKeywordsTask = task(async () => {
26+
return (await this.args.crate?.keywords) ?? [];
27+
});
28+
}
29+
130
<PageHeader class="header" data-test-heading>
231
<h1 class="heading">
332
<span data-test-crate-name>{{@crate.name}}</span>

app/components/crate-header.js

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

app/components/crate-sidebar.gjs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
import { action } from '@ember/object';
2+
import { service } from '@ember/service';
3+
import Component from '@glimmer/component';
4+
5+
import { didCancel } from 'ember-concurrency';
6+
7+
import { simplifyUrl } from './crate-sidebar/link';
8+
9+
export default class CrateSidebar extends Component {
10+
@service notifications;
11+
@service playground;
12+
@service sentry;
13+
14+
get showHomepage() {
15+
let { repository, homepage } = this.args.crate;
16+
return homepage && (!repository || simplifyUrl(repository) !== simplifyUrl(homepage));
17+
}
18+
19+
get playgroundLink() {
20+
let playgroundCrates = this.playground.crates;
21+
if (!playgroundCrates) return;
22+
23+
let playgroundCrate = playgroundCrates.find(it => it.name === this.args.crate.name);
24+
if (!playgroundCrate) return;
25+
26+
return `https://play.rust-lang.org/?edition=2021&code=use%20${playgroundCrate.id}%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20try%20using%20the%20%60${playgroundCrate.id}%60%20crate%20here%0A%7D`;
27+
}
28+
29+
get canHover() {
30+
return window?.matchMedia('(hover: hover)').matches;
31+
}
32+
33+
constructor() {
34+
super(...arguments);
35+
36+
// load Rust Playground crates list, if necessary
37+
this.playground.loadCrates().catch(error => {
38+
if (!(didCancel(error) || error.isServerError || error.isNetworkError)) {
39+
// report unexpected errors to Sentry
40+
this.sentry.captureException(error);
41+
}
42+
});
43+
}
44+
45+
@action
46+
async copyToClipboard(text) {
47+
try {
48+
await navigator.clipboard.writeText(text);
49+
this.notifications.success('Copied to clipboard!');
50+
} catch {
51+
this.notifications.error('Copy to clipboard failed!');
52+
}
53+
}
54+
}
55+
156
<section
257
aria-label="Crate metadata"
358
...attributes

app/components/crate-sidebar.js

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

app/components/crate-sidebar/install-instructions.gjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
import Component from '@glimmer/component';
2+
3+
export default class InstallInstructions extends Component {
4+
get cargoInstallCommand() {
5+
return this.args.exactVersion
6+
? `cargo install ${this.args.crate}@${this.args.version}`
7+
: `cargo install ${this.args.crate}`;
8+
}
9+
10+
get cargoAddCommand() {
11+
return this.args.exactVersion
12+
? `cargo add ${this.args.crate}@=${this.args.version}`
13+
: `cargo add ${this.args.crate}`;
14+
}
15+
16+
get tomlSnippet() {
17+
let version = this.args.version.split('+')[0];
18+
let exact = this.args.exactVersion ? '=' : '';
19+
return `${this.args.crate} = "${exact}${version}"`;
20+
}
21+
}
22+
123
{{#if @binNames}}
224
{{#if (is-clipboard-supported)}}
325
<CopyButton

app/components/crate-sidebar/install-instructions.js

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

0 commit comments

Comments
 (0)