Skip to content

Commit

Permalink
Merge pull request #9 from QuantGeekDev/feature/refactor-ternaries
Browse files Browse the repository at this point in the history
Refactor ternaries into statements to avoid nesting
  • Loading branch information
QuantGeekDev authored Jan 5, 2024
2 parents 436971d + 1cb5d51 commit 7d19abd
Showing 1 changed file with 11 additions and 6 deletions.
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
});
};

0 comments on commit 7d19abd

Please sign in to comment.