Skip to content

Commit f5e5845

Browse files
committed
render cardTypeIcon. Need to load card from code ref
1 parent c6c26ff commit f5e5845

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

Diff for: packages/base/catalog-entry.gts

+31-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import {
77
linksToMany,
88
FieldDef,
99
containsMany,
10+
type CardorFieldTypeIcon,
1011
} from './card-api';
1112
import StringField from './string';
1213
import BooleanField from './boolean';
1314
import CodeRef from './code-ref';
1415
import MarkdownField from './markdown';
16+
import { restartableTask } from 'ember-concurrency';
17+
import { LoadingIndicator } from '@cardstack/boxel-ui/components';
18+
import { loadCard } from '@cardstack/runtime-common';
1519

1620
import GlimmerComponent from '@glimmer/component';
1721
import BoxModel from '@cardstack/boxel-icons/box-model';
@@ -98,14 +102,39 @@ export class CatalogEntry extends CardDef {
98102
};
99103

100104
static isolated = class Isolated extends Component<typeof this> {
101-
get icon() {
105+
icon: CardorFieldTypeIcon | undefined;
106+
107+
get defaultIcon() {
102108
return this.args.model.constructor?.icon;
103109
}
110+
constructor(owner: any, args: any) {
111+
super(owner, args);
112+
this.loadCardIcon.perform();
113+
}
114+
115+
private loadCardIcon = restartableTask(async () => {
116+
if (this.args.model.ref && this.args.model.id) {
117+
let card = await loadCard(this.args.model.ref, {
118+
loader: (import.meta as any).loader,
119+
relativeTo: new URL(this.args.model.id),
120+
});
121+
this.icon = card.icon;
122+
}
123+
});
124+
104125
<template>
105126
<div class='container'>
106127
<div class='header'>
107128
<div class='header-icon-container'>
108-
<this.icon class='box header-icon-svg' />
129+
{{#if this.loadCardIcon.isRunning}}
130+
<LoadingIndicator class='box header-icon-svg' />
131+
{{else}}
132+
{{#if this.icon}}
133+
<this.icon class='box header-icon-svg' />
134+
{{else}}
135+
<this.defaultIcon class='box header-icon-svg' />
136+
{{/if}}
137+
{{/if}}
109138
</div>
110139
<div class='header-info-container'>
111140
<div class='box'>

0 commit comments

Comments
 (0)