Skip to content

Commit

Permalink
fix: imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Oct 18, 2024
1 parent e40c4c7 commit 04ac781
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createElement } from "react"
import { useTranslation } from "react-i18next"
import { useSearchParams } from "react-router-dom"

import { useUserRole } from "~/atoms/user"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"
import { UserRole } from "~/lib/enum"
import { cn } from "~/lib/utils"
Expand All @@ -13,17 +14,14 @@ import { Recommendations } from "~/modules/discover/recommendations"
import { DiscoverRSS3 } from "~/modules/discover/rss3-form"
import { DiscoverTransform } from "~/modules/discover/transform-form"
import { DiscoverUser } from "~/modules/discover/user-form"
import { useSettingPageContext } from "~/modules/settings/hooks/use-setting-ctx"
import type { SettingPageContext } from "~/modules/settings/utils"
import { DisableWhy } from "~/modules/settings/utils"
import { Trend } from "~/modules/trending"

import { useSubViewTitle } from "../hooks"

const tabs: {
name: I18nKeys
value: string
disableIf?: (ctx: SettingPageContext) => [boolean, DisableWhy]
disableForTrial?: boolean
}[] = [
{
name: "words.search",
Expand All @@ -40,7 +38,7 @@ const tabs: {
{
name: "words.inbox",
value: "inbox",
disableIf: (ctx) => [ctx.role === UserRole.Trial, DisableWhy.NotActivation],
disableForTrial: true,
},
{
name: "words.rss3",
Expand All @@ -65,15 +63,14 @@ export function Component() {
const { t } = useTranslation()
useSubViewTitle("words.discover")

const ctx = useSettingPageContext()
const presentActivationModal = useActivationModal()
const role = useUserRole()

const currentTabs = tabs.map((tab) => {
const [disabled, why] = tab.disableIf?.(ctx) || [false, DisableWhy.Noop]
const disabled = tab.disableForTrial && role === UserRole.Trial
return {
...tab,
disabled,
why,
}
})

Expand All @@ -97,15 +94,7 @@ export function Component() {
className={cn(tab.disabled && "cursor-not-allowed opacity-50")}
onClick={() => {
if (tab.disabled) {
switch (tab.why) {
case DisableWhy.NotActivation: {
presentActivationModal()
break
}
case DisableWhy.Noop: {
break
}
}
presentActivationModal()
}
}}
>
Expand Down

0 comments on commit 04ac781

Please sign in to comment.