generated from QuantGeekDev/ts-tg-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from QuantGeekDev/feature/property-pagination
Feature/property pagination
- Loading branch information
Showing
5 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { Composer } from "grammy"; | ||
import type { CustomContext } from "../types/context.js"; | ||
import type { Property } from "../types/database.js"; | ||
import { | ||
generatePropertyDescription, | ||
generatePropertyPhotoAlbum | ||
} from "../services/Property/property.service.js"; | ||
import { displayProperty } from "../services/Property/property.service.js"; | ||
|
||
export const propertiesController = new Composer<CustomContext>(); | ||
let currentPropertyIndex = 0; | ||
|
||
propertiesController.command("properties", async ctx => { | ||
const properties = (await ctx.db.property.find({}).toArray()) as Property[]; | ||
const currentPropertyIndex = 0; | ||
await displayProperty(ctx, properties, currentPropertyIndex); | ||
|
||
const currentProperty = properties[currentPropertyIndex]; | ||
const totalProperties = properties.length; | ||
|
||
const { videoFileId: videoUrl, albumUrls } = currentProperty; | ||
propertiesController.callbackQuery("next-property", async ctx => { | ||
ctx.answerCallbackQuery(""); | ||
if (currentPropertyIndex + 1 < properties.length) { | ||
currentPropertyIndex++; | ||
await displayProperty(ctx, properties, currentPropertyIndex); | ||
} | ||
}); | ||
|
||
const propertyDescription = generatePropertyDescription(currentProperty); | ||
const propertyPhotoAlbum = generatePropertyPhotoAlbum(albumUrls); | ||
await ctx.reply(`Property ${currentPropertyIndex + 1}/${totalProperties}`); | ||
await ctx.reply(propertyDescription, { | ||
parse_mode: "MarkdownV2" | ||
propertiesController.callbackQuery("previous-property", async ctx => { | ||
ctx.answerCallbackQuery(""); | ||
if (currentPropertyIndex + 1 > 0) { | ||
currentPropertyIndex--; | ||
await displayProperty(ctx, properties, currentPropertyIndex); | ||
} | ||
}); | ||
await ctx.replyWithVideo(videoUrl); | ||
await ctx.replyWithMediaGroup(propertyPhotoAlbum); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { InlineKeyboard } from "grammy"; | ||
|
||
export const fullPropertyControlKeyboard = new InlineKeyboard() | ||
.text("« Previous Property", "previous-property") | ||
.text("Next Property » ", "next-property"); | ||
|
||
export const nextPropertyControlKeyboard = new InlineKeyboard().text( | ||
"Next Property » ", | ||
"next-property" | ||
); | ||
|
||
export const previousPropertyControlKeyboard = new InlineKeyboard().text( | ||
"« Previous Property", | ||
"previous-property" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters