The weeb for the next gen discord boat - Wamellow wamellow.com
bot discord
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: shadcn inputs (#30)

authored by

Luna Seemann and committed by
GitHub
31ed5fed c74e11aa

+20 -8
+8 -8
app/dashboard/[guildId]/notifications/page.tsx
··· 16 16 import { Button } from "@/components/ui/button"; 17 17 import { cacheOptions } from "@/lib/api"; 18 18 import { type ApiV1GuildsModulesNotificationsGetResponse, BlueskyNotificationFlags, GuildFlags, NotificationFlags, NotificationType, YoutubeNotificationFlags } from "@/typings"; 19 - import { BitfieldManager, bitfieldToArray, transformer } from "@/utils/bitfields"; 19 + import { arrayToBitfield, BitfieldManager, bitfieldToArray, transformer } from "@/utils/bitfields"; 20 20 import { createSelectableItems } from "@/utils/create-selectable-items"; 21 21 import { getCanonicalUrl } from "@/utils/urls"; 22 22 import { LoaderCircleIcon } from "lucide-react"; ··· 218 218 : "Select the types of content to send." 219 219 } 220 220 defaultState={flags.toArray()} 221 - onSave={(o) => { 222 - const flags = o.map((flag) => Number(flag)); 223 - editItem("flags", flags.reduce((a, b) => a | b, 0)); 221 + transform={(selected) => arrayToBitfield(selected, platformFlags, item.flags)} 222 + onSave={(selected) => { 223 + const bits = arrayToBitfield(selected, platformFlags, item.flags); 224 + editItem("flags", bits); 224 225 }} 225 226 /> 226 227 : <InputText ··· 265 266 endpoint={url + "/" + item.id} 266 267 k="flags" 267 268 defaultState={(item.flags & NotificationFlags.MustNotMatchRegex) !== 0} 268 - transform={(value) => value ? [NotificationFlags.MustNotMatchRegex] : []} // very fucked up 269 + transform={(value) => transformer(value, item.flags, NotificationFlags.MustNotMatchRegex)} 269 270 onSave={(value) => editItem("flags", transformer(value, item.flags, NotificationFlags.MustNotMatchRegex))} 270 271 /> 271 272 ··· 276 277 endpoint={url + "/" + item.id} 277 278 k="flags" 278 279 defaultState={(item.flags & NotificationFlags.DeleteAfterStream) !== 0} 279 - transform={(value) => value ? [NotificationFlags.DeleteAfterStream] : []} // very fucked up 280 + transform={(value) => transformer(value, item.flags, NotificationFlags.DeleteAfterStream)} 280 281 onSave={(value) => editItem("flags", transformer(value, item.flags, NotificationFlags.DeleteAfterStream))} 281 282 /> 282 283 )} ··· 307 308 } 308 309 309 310 function TestButton( 310 - { type, creatorId, children }: 311 - { type: NotificationType; creatorId: string; children: ReactNode; } 311 + { type, creatorId, children }: { type: NotificationType; creatorId: string; children: ReactNode; } 312 312 ) { 313 313 314 314 const { data, isLoading } = useQuery(
+12
utils/bitfields.ts
··· 45 45 })); 46 46 } 47 47 48 + export function arrayToBitfield(array: (number | string)[], obj: Record<string | number, string | number>, flags: number) { 49 + const bits = array 50 + .map(Number) 51 + .reduce((a, b) => a | b, 0); 52 + 53 + const mask = Object.values(obj) 54 + .filter((v): v is number => typeof v === "number") 55 + .reduce((a, b) => a | b, 0); 56 + 57 + return (flags & ~mask) | bits; 58 + } 59 + 48 60 export function transformer(value: boolean, flags: number, flag: number) { 49 61 return value ? flags | flag : flags & ~flag; 50 62 }