|
4 | 4 | deleteMenuFromContext, getMenuOfPath, MenuTemplate, replyMenuToContext, |
5 | 5 | } from 'grammy-inline-menu'; |
6 | 6 | import {html as format} from 'telegram-format'; |
7 | | -import {count as allEventsCount, find as allEventsFind, getEventName} from '../../lib/all-events.ts'; |
| 7 | +import { |
| 8 | + count as allEventsCount, directoryExists, find as allEventsFind, getEventName, |
| 9 | +} from '../../lib/all-events.ts'; |
8 | 10 | import {filterButtonText} from '../../lib/inline-menu-filter.ts'; |
9 | 11 | import {BACK_BUTTON_TEXT} from '../../lib/inline-menu.ts'; |
10 | 12 | import type {EventDirectory, EventId, MyContext} from '../../lib/types.ts'; |
@@ -131,9 +133,22 @@ menu.choose('a', { |
131 | 133 | } |
132 | 134 |
|
133 | 135 | if (key.startsWith('d')) { |
134 | | - const chosenSubDirectory = key.slice(1); |
135 | | - ctx.session.eventPath?.push(chosenSubDirectory); |
136 | | - delete ctx.session.eventDirectorySubDirectoryItems; |
| 136 | + if (ctx.session.eventDirectorySubDirectoryItems !== undefined) { |
| 137 | + const chosenSubDirectory = ctx.session.eventDirectorySubDirectoryItems[Number(key.slice(1))]; |
| 138 | + delete ctx.session.eventDirectorySubDirectoryItems; |
| 139 | + |
| 140 | + if (chosenSubDirectory !== undefined) { |
| 141 | + ctx.session.eventPath ??= []; |
| 142 | + ctx.session.eventPath.push(chosenSubDirectory); |
| 143 | + |
| 144 | + if (directoryExists(ctx.session.eventPath)) { |
| 145 | + return true; |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + await ctx.answerCallbackQuery('Dieses Verzeichnis gibt es nicht mehr.'); |
| 151 | + delete ctx.session.eventPath; |
137 | 152 |
|
138 | 153 | return true; |
139 | 154 | } |
@@ -165,6 +180,11 @@ menu.interact('back', { |
165 | 180 | } |
166 | 181 |
|
167 | 182 | ctx.session.eventPath?.pop(); |
| 183 | + if (ctx.session.eventPath !== undefined && !directoryExists(ctx.session.eventPath)) { |
| 184 | + delete ctx.session.eventPath; |
| 185 | + delete ctx.session.eventDirectorySubDirectoryItems; |
| 186 | + } |
| 187 | + |
168 | 188 | return true; |
169 | 189 | }, |
170 | 190 | }); |
0 commit comments