Skip to content

Commit 368d954

Browse files
committed
fix first result card being mildly higher, and add a targetconfig field for additional searchable galleries
1 parent 8e6a8da commit 368d954

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

localtypings/pxtarget.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ declare namespace pxt {
2424
multiplayer?: MultiplayerConfig;
2525
// common galleries
2626
galleries?: pxt.Map<string | GalleryProps>;
27+
// additional galleries included in projects search but not shown on the homescreen
28+
searchGalleries?: pxt.Map<string | GalleryProps>;
2729
// localized galleries
2830
localizedGalleries?: pxt.Map<pxt.Map<string>>;
2931
windowsStoreLink?: string;

theme/home.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191
gap: 1rem;
192192
align-items: start;
193193
grid-auto-flow: dense;
194+
195+
// override default that's bumping it up
196+
> .ui.card:first-child {
197+
margin: 1em 0;
198+
}
194199
}
195200

196201
.search-detailview {

webapp/src/projects.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
9191
const hadNoResults = !prevState.searchResults || prevState.searchResults.length === 0;
9292
const stillNoResults = !this.state.searchResults || this.state.searchResults.length === 0;
9393
if (hadNoResults && stillNoResults) {
94-
const cards = this.collectGalleryCards(this.getHomeGalleries());
94+
const cards = this.collectGalleryCards(this.getSearchGalleries());
9595
if (cards && cards.length) {
9696
this.runSearch(this.state.searchQuery);
9797
}
@@ -118,6 +118,14 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
118118
return galleries;
119119
}
120120

121+
private getSearchGalleries(): pxt.Map<string | pxt.GalleryProps> {
122+
const targetConfig = this.getData("target-config:") as pxt.TargetConfig;
123+
const galleries = this.getHomeGalleries();
124+
if (targetConfig?.searchGalleries)
125+
pxt.Util.jsonCopyFrom(galleries, targetConfig.searchGalleries);
126+
return galleries;
127+
}
128+
121129
private collectGalleryCards(galleries: pxt.Map<string | pxt.GalleryProps>): SearchCard[] {
122130
return this.collectGallerySearchEntries(galleries).cards;
123131
}
@@ -183,7 +191,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
183191
};
184192
}
185193

186-
private collectHomeSearchEntries(galleries: pxt.Map<string | pxt.GalleryProps>) {
194+
private collectSearchEntries(galleries: pxt.Map<string | pxt.GalleryProps>) {
187195
const { cards, entries, cardMap } = this.collectGallerySearchEntries(galleries);
188196
const seen = new Set(Object.keys(cardMap));
189197

@@ -218,7 +226,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
218226

219227
private runSearch(query: string) {
220228
const normalized = (query || "").trim();
221-
const galleries = this.getHomeGalleries();
229+
const galleries = this.getSearchGalleries();
222230
const requestId = ++this.searchRequestId;
223231

224232
if (!normalized) {
@@ -229,7 +237,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
229237
return;
230238
}
231239

232-
const { entries, cardMap } = this.collectHomeSearchEntries(galleries);
240+
const { entries, cardMap } = this.collectSearchEntries(galleries);
233241
if (!entries.length) {
234242
this.setState({ searchResults: [] });
235243
return;
@@ -276,7 +284,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
276284
}
277285

278286
private warmSearchIndex() {
279-
const { entries } = this.collectHomeSearchEntries(this.getHomeGalleries());
287+
const { entries } = this.collectSearchEntries(this.getSearchGalleries());
280288
if (!entries.length) return;
281289

282290
// warm search index so that users get instant results when they start typing

0 commit comments

Comments
 (0)