diff --git a/apps/bot/src/features/core/utils.ts b/apps/bot/src/features/core/utils.ts new file mode 100644 index 0000000..fbfa823 --- /dev/null +++ b/apps/bot/src/features/core/utils.ts @@ -0,0 +1,3 @@ +export const capitalizeFirstLetter = (val: string) => { + return String(val).charAt(0).toUpperCase() + String(val).slice(1); +}; diff --git a/apps/bot/src/features/workout/workout.service.ts b/apps/bot/src/features/workout/workout.service.ts index 8e9c57b..3cf3263 100644 --- a/apps/bot/src/features/workout/workout.service.ts +++ b/apps/bot/src/features/workout/workout.service.ts @@ -22,6 +22,7 @@ import { HevyWorkout } from "@/features/hevy/hevy.types"; import { sendActivity } from "../liveActivity/liveActivity.service"; import { handleDiscordAPIError } from "../discord/error.service"; import { prisma, ShareReason, WorkoutFormat } from "@repo/db"; +import { capitalizeFirstLetter } from "../core/utils"; export const AVAILABLE_AUTO_SHARE_FORMATS: WorkoutFormat[] = [ WorkoutFormat.line, @@ -29,6 +30,11 @@ export const AVAILABLE_AUTO_SHARE_FORMATS: WorkoutFormat[] = [ WorkoutFormat.standard, ]; +export const AVAILABLE_USER_SHARABLE_FORMATS: WorkoutFormat[] = [ + WorkoutFormat.compact, + WorkoutFormat.standard, +]; + const generateButtonCustomIdSuffix = (workout: HevyWorkout, extra: string) => `${workout.short_id}-${new Date().toISOString()}-${extra}`; @@ -45,53 +51,25 @@ const sharableWorkoutEphemeralOptions = async ( components: [ workoutComponent, new ContainerBuilder().addActionRowComponents( - new ActionRowBuilder().setComponents([ - new ButtonKit() - .setLabel("Compact") - .setDisabled(format == "compact") - .setStyle(ButtonStyle.Secondary) - .setCustomId(`changeWorkoutFormat--compact--${customIdSuffix}`) - .onClick( - (i, c) => - handleMessageClick( - i as unknown as ButtonInteraction, - c, - workout, - originalInteraction, - ), - { once: true, time: 60_000 }, - ), - new ButtonKit() - .setLabel(`Standard`) - .setCustomId(`changeWorkoutFormat--standard--${customIdSuffix}`) - .setDisabled(format == "standard") - .setStyle(ButtonStyle.Secondary) - .onClick( - (i, c) => - handleMessageClick( - i as unknown as ButtonInteraction, - c, - workout, - originalInteraction, - ), - { once: true, time: 60_000 }, - ), - // new ButtonKit() - // .setLabel("Detailed") - // .setDisabled(format == "detailed") - // .setStyle(ButtonStyle.Secondary) - // .setCustomId(`changeWorkoutFormat--detailed--${customIdSuffix}`) - // .onClick( - // (i, c) => - // handleMessageClick( - // i as unknown as ButtonInteraction, - // c, - // workout, - // originalInteraction, - // ), - // { once: true, time: 60_000 }, - // ), - ]), + new ActionRowBuilder().setComponents( + AVAILABLE_USER_SHARABLE_FORMATS.map((f) => + new ButtonKit() + .setLabel(capitalizeFirstLetter(f)) + .setDisabled(format == f) + .setStyle(ButtonStyle.Secondary) + .setCustomId(`changeWorkoutFormat--${f}--${customIdSuffix}`) + .onClick( + (i, c) => + handleMessageClick( + i as unknown as ButtonInteraction, + c, + workout, + originalInteraction, + ), + { once: true, time: 60_000 }, + ), + ), + ), ), new ActionRowBuilder().setComponents([ new ButtonKit() @@ -249,7 +227,7 @@ const handleMessageClick = async ( } } } else if (interaction.customId.startsWith("changeWorkoutFormat")) { - if (["simple", "standard", "detailed"].includes(desiredFormat)) { + if (AVAILABLE_USER_SHARABLE_FORMATS.includes(desiredFormat)) { await changeWorkoutFormat( interaction as unknown as ButtonInteraction, workout, diff --git a/package.json b/package.json index fd16af4..246a2fe 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ }, "packageManager": "npm@8.5.0", "scripts": { - "bot:start": "turbo start --filter=bot --env-mode=loose", - "bot:dev": "turbo dev --filter=bot --env-mode=loose", + "bot:start": "dotenv-run -r ./.env turbo start --filter=bot --env-mode=loose", + "bot:dev": "dotenv-run -r ./.env turbo dev --filter=bot --env-mode=loose", "build": "turbo run build --env-mode=loose --summarize", "db:migrate:deploy": "turbo run db:migrate:deploy --env-mode=loose", "db:migrate:dev": "turbo run db:migrate:dev --env-mode=loose", diff --git a/turbo.json b/turbo.json index db00291..fd46d58 100644 --- a/turbo.json +++ b/turbo.json @@ -2,10 +2,11 @@ "$schema": "https://turborepo.com/schema.json", "ui": "tui", "globalDependencies": [".env"], + "envMode": "loose", "tasks": { "build": { "dependsOn": ["^build"], - "inputs": ["$TURBO_DEFAULT$", ".env*"], + "inputs": ["$TURBO_DEFAULT$", ".env"], "outputs": ["dist/**", ".next/**", "!.next/cache/**"] }, "check-types": { @@ -28,6 +29,7 @@ }, "dev": { "cache": false, + "inputs": ["$TURBO_DEFAULT$", ".env"], "persistent": true }, "start": {