@@ -26,6 +26,51 @@ import prettyBytes from 'crates-io/helpers/pretty-bytes';
2626import { simplifyUrl } from ' ./crate-sidebar/link' ;
2727
2828export default class CrateSidebar extends Component {
29+ @service notifications;
30+ @service playground;
31+ @service sentry;
32+
33+ get showHomepage () {
34+ let { repository, homepage } = this .args .crate ;
35+ return homepage && (! repository || simplifyUrl (repository) !== simplifyUrl (homepage));
36+ }
37+
38+ get playgroundLink () {
39+ let playgroundCrates = this .playground .crates ;
40+ if (! playgroundCrates) return ;
41+
42+ let playgroundCrate = playgroundCrates .find (it => it .name === this .args .crate .name );
43+ if (! playgroundCrate) return ;
44+
45+ 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` ;
46+ }
47+
48+ get canHover () {
49+ return window ? .matchMedia (' (hover: hover)' ).matches ;
50+ }
51+
52+ constructor () {
53+ super (... arguments );
54+
55+ // load Rust Playground crates list, if necessary
56+ this .playground .loadCrates ().catch (error => {
57+ if (! (didCancel (error) || error .isServerError || error .isNetworkError )) {
58+ // report unexpected errors to Sentry
59+ this .sentry .captureException (error);
60+ }
61+ });
62+ }
63+
64+ @action
65+ async copyToClipboard (text ) {
66+ try {
67+ await navigator .clipboard .writeText (text);
68+ this .notifications .success (' Copied to clipboard!' );
69+ } catch {
70+ this .notifications .error (' Copy to clipboard failed!' );
71+ }
72+ }
73+
2974 <template >
3075 <section aria-label =' Crate metadata' ...attributes class =' sidebar' >
3176 <div class =' metadata' >
@@ -173,48 +218,4 @@ export default class CrateSidebar extends Component {
173218 </div >
174219 </section >
175220 </template >
176- @service notifications;
177- @service playground;
178- @service sentry;
179-
180- get showHomepage () {
181- let { repository, homepage } = this .args .crate ;
182- return homepage && (! repository || simplifyUrl (repository) !== simplifyUrl (homepage));
183- }
184-
185- get playgroundLink () {
186- let playgroundCrates = this .playground .crates ;
187- if (! playgroundCrates) return ;
188-
189- let playgroundCrate = playgroundCrates .find (it => it .name === this .args .crate .name );
190- if (! playgroundCrate) return ;
191-
192- 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` ;
193- }
194-
195- get canHover () {
196- return window ? .matchMedia (' (hover: hover)' ).matches ;
197- }
198-
199- constructor () {
200- super (... arguments );
201-
202- // load Rust Playground crates list, if necessary
203- this .playground .loadCrates ().catch (error => {
204- if (! (didCancel (error) || error .isServerError || error .isNetworkError )) {
205- // report unexpected errors to Sentry
206- this .sentry .captureException (error);
207- }
208- });
209- }
210-
211- @action
212- async copyToClipboard (text ) {
213- try {
214- await navigator .clipboard .writeText (text);
215- this .notifications .success (' Copied to clipboard!' );
216- } catch {
217- this .notifications .error (' Copy to clipboard failed!' );
218- }
219- }
220221}
0 commit comments