fix: search continuations should return a Search class

Why? To keep things consistent.
This commit is contained in:
LuanRT
2022-06-18 05:16:21 -03:00
parent 1d2c1ed69b
commit 4c7a42d8d4
9 changed files with 244 additions and 220 deletions

View File

@@ -8,9 +8,16 @@ class Button {
constructor(data) {
this.text = new Text(data.text).toString();
this.label = data.accessibility?.label || null;
this.tooltip = data.tooltip || null;
this.icon_type = data.icon?.iconType || null;
data.accessibility?.label &&
(this.label = data.accessibility?.label);
data.tooltip &&
(this.tooltip = data.tooltip);
data.icon?.iconType &&
(this.icon_type = data.icon?.iconType);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint);
}
}

View File

@@ -61,7 +61,12 @@ class Parser {
const on_response_received_endpoints = data.onResponseReceivedEndpoints && Parser.parseRR(data.onResponseReceivedEndpoints) || null;
const on_response_received_endpoints_memo = Parser.#memo;
this.#clearMemo();
this.#createMemo();
const on_response_received_commands = data.onResponseReceivedCommands && Parser.parseRR(data.onResponseReceivedCommands) || null;
const on_response_received_commands_memo = Parser.#memo;
this.#clearMemo();
return {
contents,
contents_memo,
@@ -69,7 +74,8 @@ class Parser {
on_response_received_actions_memo,
on_response_received_endpoints,
on_response_received_endpoints_memo,
on_response_received_commands: data.onResponseReceivedCommands && Parser.parseRR(data.onResponseReceivedCommands) || null,
on_response_received_commands,
on_response_received_commands_memo,
/** @type {*} */
continuation_contents: data.continuationContents && Parser.parseLC(data.continuationContents) || null,
metadata: Parser.parse(data.metadata),

View File

@@ -29,8 +29,8 @@ class History {
this.feed_actions = secondary_contents?.contents || null;
this.sections = observe(contents.map((section) => ({
title: section.header.title,
items: section.contents
header: section.header,
contents: section.contents
})));
}

View File

@@ -26,9 +26,9 @@ class Library {
this.profile = { stats, user_info };
this.sections = observe(shelves.map((shelf) => ({
title: shelf.title.toString(),
items: shelf.content.items,
type: shelf.icon_type,
title: shelf.title.toString(),
contents: shelf.content.items,
getAll: () => this.#getAll(shelf)
})));
}

View File

@@ -41,11 +41,11 @@ class Search extends Feed {
header: card_list?.header || null,
/** @type {import('../contents/classes/SearchRefinementCard')} */
cards: card_list?.cards || []
};
}
}
/**
* Applies given refinement card and returns a new {@link Feed} object.
* Applies given refinement card and returns a new {@link Search} object.
*
* @param {import('../contents/classes/SearchRefinementCard') | string} card - refinement card object or query
* @returns {Promise.<Feed>}
@@ -66,13 +66,23 @@ class Search extends Feed {
}
const page = await target_card.endpoint.call(this.actions);
return new Feed(this.actions, page, true);
return new Search(this.actions, page, true);
}
/** @type {string[]} */
get refinement_card_queries() {
return this.refinement_cards.cards.map((card) => card.query);
}
/**
* Retrieves next batch of results.
*
* @returns {Promise.<Search>}
*/
async getContinuation() {
const continuation = await this.getContinuationData();
return new Search(this.actions, continuation, true);
}
}
module.exports = Search;