diff --git a/backend/src/bot/handlers/root.tsx b/backend/src/bot/handlers/root.tsx index 52d2bb5..5b5d04e 100644 --- a/backend/src/bot/handlers/root.tsx +++ b/backend/src/bot/handlers/root.tsx @@ -25,8 +25,6 @@ export default handler((composer) => { }) composer.use(views.main) - composer.use(views.settings) - composer.use(views.settingsLanguage) composer.use(views.trainingsDaysList) composer.use(views.trainingsDayTrainings) composer.use(views.trainingsTraining) diff --git a/backend/src/bot/handlers/views/index.ts b/backend/src/bot/handlers/views/index.ts index 509b857..d1d4ea1 100644 --- a/backend/src/bot/handlers/views/index.ts +++ b/backend/src/bot/handlers/views/index.ts @@ -1,8 +1,6 @@ import type { Context, MiddlewareFn } from 'grammy' import type { TgxElement } from '@telegum/tgx' import main from './main' -import settings from './settings' -import settingsLanguage from './settings_language' import trainingsDaysList from './trainings_days-list' import trainingsDayTrainings from './trainings_day-trainings' import trainingsTraining from './trainings_training' @@ -16,8 +14,6 @@ export type View = { export default { main, - settings, - settingsLanguage, trainingsDaysList, trainingsDayTrainings, trainingsTraining, diff --git a/backend/src/bot/handlers/views/main.tsx b/backend/src/bot/handlers/views/main.tsx index 243890d..d61fffb 100644 --- a/backend/src/bot/handlers/views/main.tsx +++ b/backend/src/bot/handlers/views/main.tsx @@ -6,7 +6,6 @@ import type { Ctx } from '~/bot/context' const VIEW_ID = 'main' -const SettingsButton = makeButton({ id: `${VIEW_ID}:settings` }) const TrainingsButton = makeButton({ id: `${VIEW_ID}:trainings` }) const SemestersButton = makeButton({ id: `${VIEW_ID}:semesters` }) @@ -20,23 +19,12 @@ export default {
-
- {ctx.t['Views.Main.Buttons.Settings']} ), middleware: () => { const composer = new Composer() - composer - .filter(SettingsButton.filter) - .use(async (ctx) => { - await ctx - .edit(ctx.from.id, ctx.msg!.message_id) - .to(await views.settings.render(ctx, {})) - ctx.answerCallbackQuery() - }) - composer .filter(TrainingsButton.filter) .use(async (ctx) => { diff --git a/backend/src/bot/handlers/views/settings.tsx b/backend/src/bot/handlers/views/settings.tsx deleted file mode 100644 index e40663f..0000000 --- a/backend/src/bot/handlers/views/settings.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Composer } from 'grammy' -import { makeButton } from '@telegum/grammy-buttons' -import type { View } from '.' -import views from '.' -import type { Ctx } from '~/bot/context' - -const VIEW_ID = 'settings' - -const BackButton = makeButton({ id: `${VIEW_ID}:back` }) -const LanguageButton = makeButton({ id: `${VIEW_ID}:language` }) - -export default { - render: async ctx => ( - <> - <>{ctx.t['Views.Settings.Message']} - - {ctx.t['Views.Settings.Buttons.Language']} -
- {ctx.t['Buttons.Back']} -
- - ), - middleware: () => { - const composer = new Composer() - - composer - .filter(LanguageButton.filter) - .use(async (ctx) => { - ctx.answerCallbackQuery() - await ctx - .edit(ctx.from.id, ctx.msg!.message_id) - .to(await views.settingsLanguage.render(ctx, {})) - }) - - composer - .filter(BackButton.filter) - .use(async (ctx) => { - ctx.answerCallbackQuery() - await ctx - .edit(ctx.from.id, ctx.msg!.message_id) - .to(await views.main.render(ctx, {})) - }) - - return composer.middleware() - }, -} satisfies View as View diff --git a/backend/src/bot/handlers/views/settings_language.tsx b/backend/src/bot/handlers/views/settings_language.tsx deleted file mode 100644 index cd59c15..0000000 --- a/backend/src/bot/handlers/views/settings_language.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { Composer } from 'grammy' -import { makeButton } from '@telegum/grammy-buttons' -import type { View } from '.' -import views from '.' -import type { Ctx } from '~/bot/context' - -const VIEW_ID = 'settings/language' - -const BackButton = makeButton({ id: `${VIEW_ID}:back` }) -const SetLanguageButton = makeButton<{ lang: 'en' | 'ru' }>({ - id: `${VIEW_ID}:set-language`, - encode: ({ lang }) => lang, - decode: lang => ({ lang: lang === 'ru' ? 'ru' : 'en' }), -}) - -export default { - render: async ctx => ( - <> - <>{ctx.t['Views.LanguageSettings.Message']} - - πŸ‡·πŸ‡Ί Русский - πŸ‡¬πŸ‡§ English -
- {ctx.t['Buttons.Back']} -
- - ), - middleware: () => { - const composer = new Composer() - - composer - .filter(SetLanguageButton.filter) - .use(async (ctx) => { - await ctx.domain.updateUser({ - telegramId: ctx.user!.telegramId, - language: ctx.payload.lang, - }) - ctx.updateLanguage(ctx.payload.lang) - ctx.answerCallbackQuery() - await ctx - .edit(ctx.from.id, ctx.msg!.message_id) - .to(await views.settings.render(ctx, {})) - }) - - composer - .filter(BackButton.filter) - .use(async (ctx) => { - ctx.answerCallbackQuery() - await ctx - .edit(ctx.from.id, ctx.msg!.message_id) - .to(await views.settings.render(ctx, {})) - }) - - return composer.middleware() - }, -} satisfies View as View diff --git a/backend/src/bot/plugins/translations.ts b/backend/src/bot/plugins/translations.ts index 723e580..a0cea01 100644 --- a/backend/src/bot/plugins/translations.ts +++ b/backend/src/bot/plugins/translations.ts @@ -5,27 +5,11 @@ import translations from '~/translations' export type TranslationsFlavor = { t: Translation - updateLanguage: (language?: Language) => void } export const install: InstallFn = (bot) => { bot.use((ctx, next) => { - ctx.updateLanguage = (language) => { - let translation - if (language) { - translation ??= translations[language] - } - if (ctx.user?.language) { - translation ??= translations[ctx.user.language as Language] - } - if (ctx.from?.language_code) { - translation ??= translations[ctx.from.language_code as Language] - } - translation ??= translations.en - ctx.t = translation - } - ctx.updateLanguage() - + ctx.t = translations[ctx.user?.language as Language] ?? translations.en return next() }) } diff --git a/backend/src/services/database/migrations/20240407143223_remove_user_language/migration.sql b/backend/src/services/database/migrations/20240407143223_remove_user_language/migration.sql new file mode 100644 index 0000000..9a74fe4 --- /dev/null +++ b/backend/src/services/database/migrations/20240407143223_remove_user_language/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `language` on the `User` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "User" DROP COLUMN "language"; diff --git a/backend/src/services/database/schema.prisma b/backend/src/services/database/schema.prisma index 7768b5d..85e57a2 100644 --- a/backend/src/services/database/schema.prisma +++ b/backend/src/services/database/schema.prisma @@ -14,8 +14,4 @@ model User { username String? firstName String lastName String? - - // Interface language user prefers as ISO 639-1 language code - // or null if user did not specify it. - language String? } diff --git a/backend/src/translations/_en.tsx b/backend/src/translations/_en.tsx index 3ce9bf4..3d63539 100644 --- a/backend/src/translations/_en.tsx +++ b/backend/src/translations/_en.tsx @@ -85,17 +85,11 @@ export default { 'Alert.CancelCheckInError': 'Error occurred during check-in cancellation.', 'Views.Main.Message': 'Hi! Here is a list of actions:', - 'Views.Main.Buttons.Settings': 'βš™οΈ Settings', 'Views.Main.Buttons.Trainings': '⛹️ Classes', 'Views.Main.Buttons.Semesters': 'πŸ“Š Semesters', 'Views.Main.Buttons.Website': '🌐 Website', 'Views.Main.Buttons.Calendar': 'πŸ“† Calendar', - 'Views.Settings.Message': 'A list of configurable things:', - 'Views.Settings.Buttons.Language': '🌐 Language', - - 'Views.LanguageSettings.Message': 'Which flag do you like more?', - 'Views.TrainingsDaysList.Message': 'Choose the date:', 'Views.DayTrainings.Message': 'Choose the class:',