Skip to content

Commit

Permalink
Fix missed code
Browse files Browse the repository at this point in the history
  • Loading branch information
sopa301 committed Dec 17, 2023
1 parent cdce511 commit 8160faa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/scenes/deleteProjectScene.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import createDebug from 'debug';

import { Markup, MiddlewareFn } from 'telegraf';
import { MiddlewareFn } from 'telegraf';

import { deleteProjectInDb } from '../db/functions';

import { BotContext, updateSessionDataBetweenScenes } from '../BotContext';
import {
askAndHandleMenuFactory,
goNextStep,
goToScene,
makeSceneWithErrorHandling,
returnToPreviousMenuFactory,
} from '../util/scene';
Expand All @@ -34,7 +35,7 @@ const map = new Map<string, MiddlewareFn<BotContext>>([
const project = getProject(ctx);
await deleteProjectInDb(project.getId());
await ctx.reply(`Project deleted.`);
return ctx.scene.enter('mainMenu', Markup.removeKeyboard());
return goToScene('mainMenu', ctx);
},
],
['No', returnToPreviousMenuFactory(previousMenu)],
Expand Down
1 change: 0 additions & 1 deletion src/scenes/editProject/editProjectScene.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import createDebug from 'debug';

import { MiddlewareFn } from 'telegraf';

import { BotContext, updateSessionDataBetweenScenes } from '../../BotContext';
Expand Down
13 changes: 9 additions & 4 deletions src/scenes/generateExistingProjectsScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
storeProjectInSession,
} from '../util/botContext';
import { isBackCommand } from '../util/userInput';
import { goNextStep, makeSceneWithErrorHandling } from '../util/scene';
import {
goNextStep,
goToScene,
makeSceneWithErrorHandling,
waitForUserResponse,
} from '../util/scene';
import { InvalidTextError } from '../exceptions';

const debug = createDebug('bot:existing_projects_command');
Expand All @@ -33,13 +38,13 @@ const askForProject = async (ctx: BotContext) => {
`Please choose an existing project that you want to view.`,
Markup.keyboard([...userProjectList, 'Back']).resize(),
);
return ctx.wizard.next();
return waitForUserResponse(ctx);
};

const handleProjectChoice = async (ctx: BotContext) => {
const text = getResponse(ctx);
if (isBackCommand(text)) {
return ctx.scene.enter(previousMenu);
return goToScene(previousMenu, ctx);
}
const projectMap = getMapFromSession(ctx);
const projectId = projectMap.get(text);
Expand All @@ -48,7 +53,7 @@ const handleProjectChoice = async (ctx: BotContext) => {
const proj = await loadProjectFromDb(projectId);
storeProjectInSession(ctx, proj);
await ctx.reply(`Loading existing project.`, Markup.removeKeyboard());
return ctx.scene.enter('manageProject', ctx.scene.session);
return goToScene('manageProject', ctx);
} else {
throw new InvalidTextError(
'Invalid option. Please select a valid option from the keyboard.',
Expand Down
8 changes: 6 additions & 2 deletions src/scenes/generateGroupingsScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { InvalidInputTypeError } from '../exceptions';
import { BotContext, updateSessionDataBetweenScenes } from '../BotContext';
import { updateProjectInDb } from '../db/functions';
import { getProject, getResponse } from '../util/botContext';
import { goToScene, makeSceneWithErrorHandling } from '../util/scene';
import {
goToScene,
makeSceneWithErrorHandling,
waitForUserResponse,
} from '../util/scene';

const debug = createDebug('bot:generate_groupings_command');
const previousMenu = 'manageProject';
Expand All @@ -18,7 +22,7 @@ const getNumGroups = async (ctx: BotContext) => {
`How many groups do you want to generate?`,
Markup.removeKeyboard(),
);
return ctx.wizard.next();
return waitForUserResponse(ctx);
};

const handleNumGroups = async (ctx: BotContext) => {
Expand Down
11 changes: 4 additions & 7 deletions src/scenes/viewMainMenuScene.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import createDebug from 'debug';
import { Markup, MiddlewareFn } from 'telegraf';
import { MiddlewareFn } from 'telegraf';

import { BotContext } from '../BotContext';
import {
askAndHandleMenuFactory,
goNextStep,
goToScene,
makeSceneWithErrorHandling,
} from '../util/scene';

Expand All @@ -17,14 +18,10 @@ const mainMenu = async (ctx: BotContext, next: () => Promise<void>) => {

const question = `What do you want to do?`;
const map = new Map<string, MiddlewareFn<BotContext>>([
[
'Create New Project',
async (ctx) => ctx.scene.enter('addProject', Markup.removeKeyboard()),
],
['Create New Project', async (ctx) => goToScene('addProject', ctx)],
[
'View Existing Project(s)',
async (ctx) =>
ctx.scene.enter('existingProjects', Markup.removeKeyboard()),
async (ctx) => goToScene('existingProjects', ctx),
],
]);

Expand Down

0 comments on commit 8160faa

Please sign in to comment.