Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/navigation and state mgmt #32

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: localize cli prompt
vinnyA3 committed Oct 2, 2022
commit 5547057e52229c08a9df73f3e715838a98397d02
18 changes: 11 additions & 7 deletions src/navigation/screens/search/index.ts
Original file line number Diff line number Diff line change
@@ -20,19 +20,23 @@ const {
processing: { searchAnime },
} = Gogoanime;

const inputAnimePrompt = [
{
type: "input",
name: "inputAnimeName",
message: "Please type the name of your desired anime",
},
];

class Search {
constructor() {
this.render();
}

private async prompt() {
const { inputAnimeName }: { inputAnimeName: string } = await prompt([
{
type: "input",
name: "inputAnimeName",
message: "Please type the name of your desired anime",
},
]);
const { inputAnimeName }: { inputAnimeName: string } = await prompt(
inputAnimePrompt
);

return inputAnimeName;
}
38 changes: 21 additions & 17 deletions src/navigation/screens/select-result/index.ts
Original file line number Diff line number Diff line change
@@ -4,39 +4,43 @@ import { prompt } from "enquirer";
// import Navigator from "../../navigator";

export type SelectResultsParams = {
searchResults?: string[];
searchResults: string[];
};

export const createSelectResultsParams = ({
searchResults = [],
}: {
searchResults?: string[];
searchResults: string[];
}): SelectResultsParams => ({ searchResults });

const selectResultPrompt = (choices: string[]) => [
{
type: "autocomplete",
name: "chosenTitle",
message: "Select a title to Stream",
initial: 1,
choices,
},
];

class SelectResults {
private params?: SelectResultsParams;
private params: SelectResultsParams = { searchResults: [] };

constructor(params?: SelectResultsParams) {
constructor(params: SelectResultsParams) {
this.params = params;
this.render();
}

private async prompt(choices?: string[]) {
const selected = await prompt([
{
type: "autocomplete",
name: "chosenTitle",
message: "Select a title to stream",
initial: 1,
choices,
},
]).then((res: { chosenTitle?: string }) => res.chosenTitle || "");

return selected;
private async prompt(choices: string[]) {
const selected = await prompt(selectResultPrompt(choices)).then(
(res: { chosenTitle?: string }) => res.chosenTitle
);

return selected || "";
}

render = async () => {
const selectedTitle = await this.prompt(this.params?.searchResults);
const selectedTitle = await this.prompt(this.params.searchResults);
console.log(selectedTitle);
};
}