Skip to content

Commit

Permalink
refactor: remove settings and user language
Browse files Browse the repository at this point in the history
  • Loading branch information
evermake committed Apr 7, 2024
1 parent a3cb687 commit fd8978f
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 147 deletions.
2 changes: 0 additions & 2 deletions backend/src/bot/handlers/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions backend/src/bot/handlers/views/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,8 +14,6 @@ export type View<C extends Context, P = {}> = {

export default {
main,
settings,
settingsLanguage,
trainingsDaysList,
trainingsDayTrainings,
trainingsTraining,
Expand Down
12 changes: 0 additions & 12 deletions backend/src/bot/handlers/views/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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` })

Expand All @@ -20,23 +19,12 @@ export default {
<br />
<button url="https://innohassle.ru/sport">{ctx.t['Views.Main.Buttons.Calendar']}</button>
<button url="https://sport.innopolis.university">{ctx.t['Views.Main.Buttons.Website']}</button>
<br />
<SettingsButton>{ctx.t['Views.Main.Buttons.Settings']}</SettingsButton>
</keyboard>
</>
),
middleware: () => {
const composer = new Composer<Ctx>()

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) => {
Expand Down
46 changes: 0 additions & 46 deletions backend/src/bot/handlers/views/settings.tsx

This file was deleted.

56 changes: 0 additions & 56 deletions backend/src/bot/handlers/views/settings_language.tsx

This file was deleted.

18 changes: 1 addition & 17 deletions backend/src/bot/plugins/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@ import translations from '~/translations'

export type TranslationsFlavor = {
t: Translation
updateLanguage: (language?: Language) => void
}

export const install: InstallFn<TranslationsFlavor & DomainFlavor> = (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()
})
}
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 0 additions & 4 deletions backend/src/services/database/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
6 changes: 0 additions & 6 deletions backend/src/translations/_en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand Down

0 comments on commit fd8978f

Please sign in to comment.