1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
import { isNothing } from "@jet/environment/types/optional";
import * as models from "../../../api/models";
import * as serverData from "../../../foundation/json-parsing/server-data";
import { Parameters, Path, Protocol } from "../../../foundation/network/url-constants";
import * as metricsHelpersClicks from "../../metrics/helpers/clicks";
import * as metricsHelpersImpressions from "../../metrics/helpers/impressions";
import * as metricsHelpersLocation from "../../metrics/helpers/location";
import * as searchLandingShelfController from "../landing/search-landing-shelf-controller";
/**
* The `SearchHistoryShelfToken` type is responsible for plumbing through all
* the data needed to render an incomplete shelf (a shelf that requires a
* lookup) on the focus page.
*/
export class SearchHistoryShelfToken {
constructor(title, maxItems, shelfDisplayStyle, itemDisplayStyle) {
this.title = title;
this.maxItems = maxItems;
this.shelfDisplayStyle = shelfDisplayStyle;
this.itemDisplayStyle = itemDisplayStyle;
}
}
function encodedShelfToken(token) {
return encodeURIComponent(JSON.stringify(token));
}
export function decodeShelfToken(json) {
if (isNothing(json)) {
return undefined;
}
return JSON.parse(decodeURIComponent(json));
}
export function createShelfWithContext(objectGraph, pageContext, shelfAttributes) {
const token = new SearchHistoryShelfToken(shelfAttributes.title, shelfAttributes.displayCount, shelfAttributes.displayStyle, shelfAttributes.searchLandingItemDisplayStyle);
return createShelfWithToken(objectGraph, token, pageContext.metricsPageInformation, pageContext.metricsLocationTracker, pageContext.searchHistory);
}
function createShelfItems(objectGraph, metricsPageInformation, metricsLocationTracker, itemDisplayStyle, searchHistory) {
if (serverData.isNullOrEmpty(searchHistory)) {
return [];
}
const items = [];
for (const [historyIndex, historyItem] of searchHistory.entries()) {
const item = createShelfItem(objectGraph, historyItem, historyIndex, metricsPageInformation, metricsLocationTracker, itemDisplayStyle);
if (serverData.isNullOrEmpty(item)) {
continue;
}
items.push(item);
metricsHelpersLocation.nextPosition(metricsLocationTracker);
}
return items;
}
function createShelfURL(token) {
return `${Protocol.internal}:/${Path.searchLandingPage}/${Path.shelf}/?${Parameters.isOnDeviceSearchHistoryShelf}=true&${Parameters.token}=${encodedShelfToken(token)}`;
}
export function createShelfWithToken(objectGraph, token, metricsPageInformation, metricsLocationTracker, searchHistory) {
// Create Items
const items = createShelfItems(objectGraph, metricsPageInformation, metricsLocationTracker, token.itemDisplayStyle, searchHistory);
// Clear History Action
const clearHistoryAction = new models.ClearSearchHistoryAction();
clearHistoryAction.title = objectGraph.loc.string("Action.ClearSearches");
metricsHelpersClicks.addClickEventToClearSearchHistoryAction(objectGraph, clearHistoryAction);
// Clear History Sheet Action
const clearHistorySheetAction = new models.SheetAction([clearHistoryAction]);
clearHistorySheetAction.title = objectGraph.loc.string("Sheet.ClearSearches.Title");
clearHistorySheetAction.message = objectGraph.loc.string("Sheet.ClearSearches.Message");
clearHistorySheetAction.destructiveActionIndex = 0;
clearHistorySheetAction.isCancelable = true;
// Clear History Compound Action
const clearHistoryShelfAction = new models.CompoundAction([clearHistorySheetAction]);
clearHistoryShelfAction.title = objectGraph.loc.string("Action.Clear");
// Shelf
const contentType = shelfContentTypeForDisplayStyle(token.shelfDisplayStyle);
const shelf = new models.Shelf(contentType);
shelf.id = "onDeviceSearchHistory";
shelf.presentationHints = { isWidthConstrained: true };
// Header
shelf.header = {
title: token.title,
accessoryAction: clearHistoryShelfAction,
};
// Grid
if (shelf.contentType === "scrollablePill") {
shelf.isHorizontal = true;
shelf.rowsPerColumn = token.shelfDisplayStyle.layoutSize;
}
shelf.contentsMetadata = {
type: "searchFocusTwoColumnList",
numberOfColumns: items.length > 1 ? token.shelfDisplayStyle.layoutSize : 1,
};
// Content
shelf.items = items;
shelf.isHidden = serverData.isNullOrEmpty(items);
shelf.refreshUrl = createShelfURL(token);
return shelf;
}
function shelfContentTypeForDisplayStyle(displayStyle) {
if (displayStyle.layout === "word_cloud" /* models.GenericSearchPageShelfDisplayStyleLayout.WordCloud */) {
return "scrollablePill";
}
if (displayStyle.layoutSize === 2) {
// MAINTAINER'S NOTE: Automatically renders as single column in AX text sizes.
return "twoColumnList";
}
return "singleColumnList";
}
function createItemTitle(objectGraph, searchTerm, searchEntity) {
if (isNothing(searchEntity)) {
return searchTerm;
}
let formatLocKey;
if (searchEntity === "developer") {
formatLocKey = "Search.ResultsTitle.InDevelopers";
}
else if (searchEntity === "story") {
formatLocKey = "Search.ResultsTitle.InStories";
}
else if (searchEntity === "watch") {
formatLocKey = "Search.ResultsTitle.InWatch";
}
else if (searchEntity === "arcade") {
formatLocKey = "Search.ResultsTitle.InArcade";
}
if (isNothing(formatLocKey)) {
return searchTerm;
}
return objectGraph.loc.string(formatLocKey).replace("@@search_term@@", searchTerm);
}
function createShelfItem(objectGraph, historyItem, itemIndex, metricsPageInformation, metricsLocationTracker, displayStyle) {
const searchTerm = historyItem.term;
const searchEntity = historyItem.entity;
const searchAction = searchLandingShelfController.createFocusPageSearchAction(objectGraph, createItemTitle(objectGraph, searchTerm, searchEntity), searchTerm, searchEntity, metricsLocationTracker, "recents", undefined, /// MAINTAINER'S NOTE: In the future, we could keep track of the original search source and attribute this recent search to that.
metricsPageInformation, displayStyle);
if (isNothing(searchAction)) {
return null;
}
searchAction.id = historyItem.id;
metricsHelpersImpressions.addImpressionFields(objectGraph, searchAction, {
targetType: "link",
pageInformation: metricsPageInformation,
locationTracker: metricsLocationTracker,
kind: "link",
softwareType: null,
title: historyItem.term,
hintsEntity: historyItem.entity,
id: `${itemIndex}`,
idType: "sequential",
});
return searchAction;
}
//# sourceMappingURL=search-history-shelf.js.map
|