Skip to content

Commit

Permalink
cleanup: remove unnecessary as PlatformName casts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Sep 20, 2024
1 parent 38d47d6 commit f1c7e97
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/components/[guild]/JoinModal/JoinModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import dynamic from "next/dynamic"
import { ComponentType, Fragment } from "react"
import { FormProvider, useForm } from "react-hook-form"
import rewards from "rewards"
import { PlatformName } from "types"
import { ConnectPlatform } from "./components/ConnectPlatform"
import { ShareSocialsCheckbox } from "./components/ShareSocialsCheckbox"
import { WalletAuthButton } from "./components/WalletAuthButton"
Expand Down Expand Up @@ -74,7 +73,7 @@ const JoinModal = ({

return (
<Fragment key={platform}>
<ConnectPlatform platform={platform as PlatformName} />
<ConnectPlatform platform={platform} />
{shouldRenderSeparator && <Separator />}
</Fragment>
)
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/ContractCall/useContractCallCardProps.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useNftDetails from "components/[guild]/collect/hooks/useNftDetails"
import useGuild from "components/[guild]/hooks/useGuild"
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"
import NftAvailabilityTags from "./components/NftAvailabilityTags"

const useContractCallCardProps: CardPropsHook = (
Expand All @@ -16,7 +16,7 @@ const useContractCallCardProps: CardPropsHook = (
.find((rp) => rp.guildPlatformId === guildPlatform.id)

return {
type: "CONTRACT_CALL" as PlatformName,
type: "CONTRACT_CALL",
name,
image,
info: rolePlatform && (
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/Forms/useFormCardProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { useGuildForm } from "components/[guild]/hooks/useGuildForms"
import useGuildPermission from "components/[guild]/hooks/useGuildPermission"
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"
import pluralize from "utils/pluralize"
import { formData } from "./data"

Expand All @@ -21,7 +21,7 @@ const useFormCardProps: CardPropsHook = (
const { form, isSigned } = useGuildForm(guildPlatform?.platformGuildData?.formId)

return {
type: "FORM" as PlatformName,
type: "FORM",
image: (
<Circle size={10} bgColor={circleBgColor}>
<Icon as={formData?.icon} color="white" />
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/Gather/useGatherCardProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Circle, Img, useColorModeValue } from "@chakra-ui/react"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import { CardPropsHook } from "rewards/types"
import { GuildPlatform, PlatformName } from "types"
import { GuildPlatform } from "types"
import { gatherData } from "./data"

const useGatherCardProps: CardPropsHook = (guildPlatform: GuildPlatform) => {
Expand All @@ -15,7 +15,7 @@ const useGatherCardProps: CardPropsHook = (guildPlatform: GuildPlatform) => {
.find((rp) => rp.guildPlatformId === guildPlatform.id)
return {
name: guildPlatform.platformGuildData?.name ?? gatherData.name,
type: "GATHER_TOWN" as PlatformName,
type: "GATHER_TOWN",
image: (
<Circle size={10} bgColor={bgColor} overflow="hidden">
<Img src={gatherData.imageUrl} boxSize={10} color="white" />
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/Github/useGithubCardProps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"

const useGithubCardProps: CardPropsHook = (
guildPlatform: GuildPlatformWithOptionalId
) => ({
type: "GITHUB" as PlatformName,
type: "GITHUB",
name: decodeURIComponent(guildPlatform.platformGuildId),
link: `https://github.com/${decodeURIComponent(guildPlatform.platformGuildId)}`,
})
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/Google/useGoogleCardProps.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Circle, Img, useColorModeValue } from "@chakra-ui/react"
import { useRolePlatform } from "components/[guild]/RolePlatforms/components/RolePlatformProvider"
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"
import { googleData } from "./data"

const fileTypeNames = {
Expand Down Expand Up @@ -46,7 +46,7 @@ const useGoogleCardProps: CardPropsHook = (
: ""

return {
type: "GOOGLE" as PlatformName,
type: "GOOGLE",
image: guildPlatform.platformGuildData?.iconLink ? (
<Circle size={10} bgColor={imageBgColor}>
<Img
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/Poap/usePoapCardProps.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"
import { poapData } from "./data"

const usePoapCardProps: CardPropsHook = (
Expand All @@ -16,7 +16,7 @@ const usePoapCardProps: CardPropsHook = (

return {
name: platformGuildData?.name || poapData.name,
type: "POAP" as PlatformName,
type: "POAP",
image: platformGuildData?.imageUrl || poapData.imageUrl,
info: rolePlatform && <AvailabilityTags rolePlatform={rolePlatform} mt={1} />,
}
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/SecretText/useSecretTextCardProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Circle, Icon, useColorModeValue } from "@chakra-ui/react"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import { CardPropsHook } from "rewards/types"
import { GuildPlatformWithOptionalId, PlatformName } from "types"
import { GuildPlatformWithOptionalId } from "types"
import { secretTextData } from "./data"

const useSecretTextCardProps: CardPropsHook = (
Expand All @@ -19,7 +19,7 @@ const useSecretTextCardProps: CardPropsHook = (

return {
name: platformGuildData?.name || secretTextData.name,
type: "TEXT" as PlatformName,
type: "TEXT",
image: platformGuildData?.imageUrl ?? (
<Circle size={10} bgColor={bgColor}>
<Icon as={secretTextData.icon} boxSize={5} color="white" />
Expand Down
4 changes: 2 additions & 2 deletions src/solutions/components/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const Category = ({
{...item}
onClick={
item.handlerType === "reward"
? () => onSelectReward(item.handlerParam as PlatformName)
: () => onSelectSolution(item.handlerParam as SolutionName)
? () => onSelectReward(item.handlerParam)
: () => onSelectSolution(item.handlerParam)
}
/>
</CardMotionWrapper>
Expand Down
15 changes: 12 additions & 3 deletions src/solutions/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { PlatformName } from "@guildxyz/types"
import { categories, solutions } from "solutions"
import { OneOf } from "types"

export type SolutionName = keyof typeof solutions

type HandlerTypeAndParam = OneOf<
{
handlerType: "reward"
handlerParam: Exclude<PlatformName, "GUILD_PIN" | "WORLD_ID">
},
{
handlerType: "solution"
handlerParam: SolutionName
}
>
export type SolutionCardData = {
title: string
description: string
imageUrl: string
bgImageUrl: string
handlerType: "reward" | "solution"
handlerParam: PlatformName | SolutionName
}
} & HandlerTypeAndParam

export type CategoryValue = (typeof categories)[number]["value"]
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const ConnectPlatformButton = ({
}

const { isLoading, response, onConnect } = useConnectPlatform(
type as PlatformName,
type,
onSuccess,
isReconnect
)
Expand Down

0 comments on commit f1c7e97

Please sign in to comment.