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 ternaries into statements to avoid nesting #9

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/services/Property/property.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
nextPropertyControlKeyboard,
previousPropertyControlKeyboard
} from "../../menus/propertyMenu.js";
import type { CustomContext } from "../../types/context.js";

export const generatePropertyDescription = (property: Property): string => {
const {
Expand Down Expand Up @@ -49,6 +50,15 @@ export const displayProperty = async (
const currentProperty = properties[currentPropertyIndex];
const { videoFileId, albumUrls } = currentProperty;

let controlKeyboard;
if (currentPropertyIndex == 0) {
controlKeyboard = nextPropertyControlKeyboard;
} else if (currentPropertyIndex + 1 < totalProperties) {
controlKeyboard = fullPropertyControlKeyboard;
} else {
controlKeyboard = previousPropertyControlKeyboard;
}

const propertyDescription = generatePropertyDescription(currentProperty);
const propertyPhotoAlbum = generatePropertyPhotoAlbum(albumUrls);

Expand All @@ -57,11 +67,6 @@ export const displayProperty = async (
await ctx.replyWithVideo(videoFileId);
await ctx.replyWithMediaGroup(propertyPhotoAlbum);
await ctx.reply(`Property ${currentPropertyIndex + 1}/${totalProperties}`, {
reply_markup:
currentPropertyIndex == 0
? nextPropertyControlKeyboard
: currentPropertyIndex + 1 < totalProperties
? fullPropertyControlKeyboard
: previousPropertyControlKeyboard
reply_markup: controlKeyboard
});
};
Loading