summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/common/room/room-common.js
blob: d1ab4a0659f18889fd0654eb04101d9f55be5f54 (plain)
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
import { makeRoomPageIntent } from "../../api/intents/room-page-intent";
import * as models from "../../api/models";
import * as mediaDataFetching from "../../foundation/media/data-fetching";
import { AbstractMediaApiPageBuilder } from "../builders/abstract-media-api-page-builder";
import * as pagination from "../builders/pagination";
import * as metricsHelpersLocation from "../metrics/helpers/location";
import * as metricsHelpersPage from "../metrics/helpers/page";
import { generateRoutes } from "../util/generate-routes";
import { defaultAttributesForRoomRequest } from "./room-request";
import { withAsyncValidationContext } from "../../foundation/util/validation-util";
import { defaultRoomShelfContentType, roomPageWithContent } from "./room-page";
export class RoomPageToken {
    constructor() {
        /// The store platform data profile to use.
        this.profile = "lockup";
        /// The maximum number of ids to fetch per load more request.
        this.maxPerPage = pagination.suggestedMaxPerPage;
    }
}
export class AbstractRoomBuilder extends AbstractMediaApiPageBuilder {
    //
    // Begin Region: Common
    //
    defaultAttributes(objectGraph) {
        return defaultAttributesForRoomRequest(objectGraph);
    }
    defaultPlatforms(objectGraph) {
        return mediaDataFetching.defaultAdditionalPlatformsForClient(objectGraph);
    }
    pageType() {
        return "page";
    }
    //
    // Begin Region: Load More
    //
    generatePaginationRequest(objectGraph, url, parameters, token) {
        const pageToken = token;
        const mediaApiRequest = new mediaDataFetching.Request(objectGraph, pageToken.remainingContent);
        return mediaApiRequest;
    }
    async renderPaginatedPage(objectGraph, data, token) {
        const pageToken = token;
        return await this.pageWithContent(objectGraph, data, pageToken);
    }
    //
    // Begin Region: Internal API
    //
    /**
     * Generates a room page given a list of lockups
     *
     * @param {DataContainer} roomContents
     * @param {RoomPageToken} token The token representing the content to load
     * @param {boolean} shouldUpdateRemainingContent Whether to update the remaining content in the token,
     * false when being handled outside of this method
     * @returns {GenericPage}
     */
    async pageWithContent(objectGraph, roomContents, token, shouldUpdateRemainingContent = true) {
        return await withAsyncValidationContext("pageWithContent", async () => {
            return roomPageWithContent(objectGraph, roomContents, token, shouldUpdateRemainingContent);
        });
    }
}
/**
 * Creates a page that can be used for side-packing see all pages into a room.
 *
 * @param objectGraph
 * @param {string} title The title of the destination page
 * @param {ShelfContentType} preferredShelfContentType The content type to use for the page
 * @returns {GenericPage} A GenericPage which will use the parentShelfItems from the see all to render the initial room
 */
export function seeAllPage(objectGraph, title, preferredShelfContentType) {
    const shelf = new models.Shelf(preferredShelfContentType || defaultRoomShelfContentType);
    shelf.isHorizontal = false;
    shelf.items = "parentShelfItems";
    const page = new models.GenericPage([shelf]);
    page.isIncomplete = true;
    page.title = title;
    if (platformPrefersLargeTitles(objectGraph)) {
        page.presentationOptions = ["prefersLargeTitle"];
    }
    return page;
}
export function platformPrefersLargeTitles(objectGraph) {
    return objectGraph.client.isWatch || objectGraph.client.isMac;
}
export class AbstractActionRoomBuilder extends AbstractRoomBuilder {
    async handlePage(objectGraph, url, parameters, matchedRuleIdentifier, referrerData, isIncomingURL) {
        return this.action();
    }
    generatePageRequest(objectGraph, url, parameters) {
        throw new Error(`generatePageRequest is not supported on: ${this.builderClass}`);
    }
    async renderPage(objectGraph, data, parameters, additionalPageRequirements) {
        throw new Error(`renderPage is not supported on: ${this.builderClass}`);
    }
}
export class AbstractFilteredRoom extends AbstractRoomBuilder {
    requestWithFilter(objectGraph, type, value) {
        const mediaApiRequest = new mediaDataFetching.Request(objectGraph)
            .forType("apps")
            .includingMacOSCompatibleIOSAppsWhenSupported(true)
            .withFilter(type, value);
        return mediaApiRequest;
    }
    async renderPage(objectGraph, data, parameters, additionalPageRequirements) {
        return await withAsyncValidationContext("renderPage", async () => {
            // Create the token
            const token = new RoomPageToken();
            token.url = this.paginationUrl;
            token.metricsPageInformation = this.pageInformation(objectGraph, data, parameters);
            token.shouldFilter = false;
            token.metricsLocationTracker = metricsHelpersLocation.newLocationTracker();
            const page = await this.pageWithContent(objectGraph, data, token);
            metricsHelpersPage.addMetricsEventsToPageWithInformation(objectGraph, page, token.metricsPageInformation);
            return page;
        });
    }
}
/// MARK: `RoomPageIntentController` Routing
const { routes: roomPageRoutesWithoutPlatform, makeCanonicalUrl: makeCanonicalRoomPageUrlWithoutPlatform } = generateRoutes(makeRoomPageIntent, "/room/{id}");
const { routes: roomPageRoutesWithPlatform, makeCanonicalUrl: makeCanonicalRoomPageUrlWithPlatform } = generateRoutes(makeRoomPageIntent, "/{platform}/room/{id}");
/**
 * Define the `RouteProvider` routes for the `RoomPageIntentController`
 */
export function roomPageRoutes(objectGraph) {
    return [...roomPageRoutesWithoutPlatform(objectGraph), ...roomPageRoutesWithPlatform(objectGraph)];
}
/**
 * Generate the URL used by the "web" client to route to a {@linkcode RoomPageIntent}
 */
export function makeCanonicalRoomPageUrl(objectGraph, intent) {
    if ("platform" in intent) {
        return makeCanonicalRoomPageUrlWithPlatform(objectGraph, intent);
    }
    else {
        return makeCanonicalRoomPageUrlWithoutPlatform(objectGraph, intent);
    }
}
//# sourceMappingURL=room-common.js.map