mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-03 06:35:42 -05:00
Fix joining q directly on Safari 15 crashing
This commit is contained in:
parent
c2b72246d0
commit
082d732b3f
|
|
@ -7,6 +7,7 @@ import {
|
|||
import {
|
||||
_action,
|
||||
checkboxValueToBoolean,
|
||||
deduplicate,
|
||||
id,
|
||||
safeJSONParse,
|
||||
weaponSplId,
|
||||
|
|
@ -18,7 +19,7 @@ export const frontPageSchema = z.union([
|
|||
_action: _action("JOIN_QUEUE"),
|
||||
mapListPreference: z.enum(MAP_LIST_PREFERENCE_OPTIONS),
|
||||
mapPool: z.string(),
|
||||
direct: z.literal("true").nullish(),
|
||||
direct: z.preprocess(deduplicate, z.literal("true").nullish()),
|
||||
}),
|
||||
z.object({
|
||||
_action: _action("JOIN_TEAM"),
|
||||
|
|
|
|||
|
|
@ -188,14 +188,17 @@ export function checkboxValueToDbBoolean(value: unknown) {
|
|||
}
|
||||
|
||||
export const _action = <T extends z.Primitive>(value: T) =>
|
||||
z.preprocess((valueToParse) => {
|
||||
if (typeof valueToParse === "string") return valueToParse;
|
||||
// Fix bug at least in Safari 15 where SubmitButton value might get sent twice
|
||||
if (Array.isArray(valueToParse)) {
|
||||
const [one, two, ...rest] = valueToParse;
|
||||
if (rest.length > 0) return valueToParse;
|
||||
if (one !== two) return valueToParse;
|
||||
z.preprocess(deduplicate, z.literal(value));
|
||||
|
||||
return one;
|
||||
}
|
||||
}, z.literal(value));
|
||||
// Fix bug at least in Safari 15 where SubmitButton value might get sent twice
|
||||
export function deduplicate(value: unknown) {
|
||||
if (Array.isArray(value)) {
|
||||
const [one, two, ...rest] = value;
|
||||
if (rest.length > 0) return value;
|
||||
if (one !== two) return value;
|
||||
|
||||
return one;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user