diff --git a/app/db/tables.ts b/app/db/tables.ts index 0b7c2896f..da0a1b3f9 100644 --- a/app/db/tables.ts +++ b/app/db/tables.ts @@ -321,6 +321,7 @@ export interface LFGPost { authorId: number; teamId: number | null; plusTierVisibility: number | null; + languages: string | null; updatedAt: Generated; createdAt: GeneratedAlways; } diff --git a/app/features/lfg/LFGRepository.server.ts b/app/features/lfg/LFGRepository.server.ts index becab4d21..56faf78f1 100644 --- a/app/features/lfg/LFGRepository.server.ts +++ b/app/features/lfg/LFGRepository.server.ts @@ -24,6 +24,7 @@ export async function posts(user?: { id: number; plusTier: number | null }) { "LFGPost.createdAt", "LFGPost.updatedAt", "LFGPost.plusTierVisibility", + "LFGPost.languages", jsonObjectFrom( eb .selectFrom("User") @@ -128,6 +129,7 @@ export function updatePost( timezone: args.timezone, type: args.type, plusTierVisibility: args.plusTierVisibility, + languages: args.languages, updatedAt: dateToDatabaseTimestamp(new Date()), }) .where("id", "=", postId) diff --git a/app/features/lfg/actions/lfg.new.server.ts b/app/features/lfg/actions/lfg.new.server.ts index fb0783633..abfa8f44d 100644 --- a/app/features/lfg/actions/lfg.new.server.ts +++ b/app/features/lfg/actions/lfg.new.server.ts @@ -5,7 +5,8 @@ import { requireUser } from "~/features/auth/core/user.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import { errorToastIfFalsy, parseRequestPayload } from "~/utils/remix.server"; import { LFG_PAGE } from "~/utils/urls"; -import { falsyToNull, id } from "~/utils/zod"; +import { falsyToNull, id, noDuplicates, safeJSONParse } from "~/utils/zod"; +import { languagesUnified } from "../../../modules/i18n/config"; import * as LFGRepository from "../LFGRepository.server"; import { LFG, TEAM_POST_TYPES, TIMEZONES } from "../lfg-constants"; @@ -39,6 +40,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { type: data.type, teamId: shouldIncludeTeam ? team?.id : null, plusTierVisibility: data.plusTierVisibility, + languages: data.languages.length > 0 ? data.languages.join(",") : null, }); } else { await LFGRepository.insertPost({ @@ -48,6 +50,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { teamId: shouldIncludeTeam ? team?.id : null, authorId: user.id, plusTierVisibility: data.plusTierVisibility, + languages: data.languages.length > 0 ? data.languages.join(",") : null, }); } @@ -63,6 +66,15 @@ const schema = z.object({ falsyToNull, z.coerce.number().int().min(1).max(3).nullish(), ), + languages: z.preprocess( + safeJSONParse, + z + .array(z.string()) + .refine(noDuplicates) + .refine((val) => + val.every((lang) => languagesUnified.some((l) => l.code === lang)), + ), + ), }); const validateCanUpdatePost = async ({ diff --git a/app/features/lfg/components/LFGFilters.tsx b/app/features/lfg/components/LFGFilters.tsx index 19bcd0b14..13aae6f16 100644 --- a/app/features/lfg/components/LFGFilters.tsx +++ b/app/features/lfg/components/LFGFilters.tsx @@ -56,7 +56,7 @@ function Filter({ return (
-