Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban authored Oct 21, 2024
2 parents 441ecaf + 93461e8 commit 5084de9
Show file tree
Hide file tree
Showing 46 changed files with 796 additions and 888 deletions.
2 changes: 0 additions & 2 deletions apps/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"msedge-tts": "1.3.4",
"nanoid": "5.0.7",
"ofetch": "1.4.1",
"posthog-js": "1.169.0",
"posthog-node": "4.2.1",
"semver": "7.6.3",
"vscode-languagedetection": "npm:@vscode/vscode-languagedetection@^1.0.22"
},
Expand Down
1 change: 0 additions & 1 deletion apps/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"nanoid": "5.0.7",
"ofetch": "1.4.1",
"path-to-regexp": "8.2.0",
"posthog-js": "1.169.1",
"re-resizable": "6.10.0",
"react-blurhash": "^0.3.0",
"react-error-boundary": "4.0.13",
Expand Down
8 changes: 8 additions & 0 deletions apps/renderer/src/atoms/server-configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { atom } from "jotai"

import { createAtomHooks } from "~/lib/jotai"
import type { ServerConfigs } from "~/models"

export const [, , useServerConfigs, , getServerConfigs, setServerConfigs] = createAtomHooks(
atom<Nullable<ServerConfigs>>(null),
)
1 change: 0 additions & 1 deletion apps/renderer/src/components/icons/users.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { SVGProps } from "react"
import React from "react"

export function PhUsersBold(props: SVGProps<SVGSVGElement>) {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/components/ui/fab/FABContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { typescriptHappyForwardRef } from "foxact/typescript-happy-forward-ref"
import type { HTMLMotionProps } from "framer-motion"
import { AnimatePresence } from "framer-motion"
import { atom, useAtomValue } from "jotai"
import type React from "react"
import type * as React from "react"
import type { JSX, PropsWithChildren, ReactNode } from "react"
import { useId } from "react"

Expand Down
3 changes: 2 additions & 1 deletion apps/renderer/src/components/ui/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { m, useAnimation } from "framer-motion"
import React, { cloneElement, useEffect } from "react"
import * as React from "react"
import { cloneElement, useEffect } from "react"

import { cn } from "~/lib/utils"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const MarkdownBlockImage = (
<Media
type="photo"
{...props}
loading="lazy"
src={src}
height={media?.height || props.height}
width={media?.width || props.width}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const MarkdownInlineImage = (
<Media
type="photo"
{...props}
loading="lazy"
src={populatedUrl}
mediaContainerClassName={cn("inline max-w-full rounded-md")}
popper
Expand Down
99 changes: 52 additions & 47 deletions apps/renderer/src/components/ui/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const tabsTriggerVariants = cva("", {
variant: {
default:
"py-1.5 border-b-2 border-transparent data-[state=active]:text-accent dark:data-[state=active]:text-theme-accent-500",
rounded:
"py-1 rounded-sm data-[state=active]:bg-theme-accent-300 dark:data-[state=active]:bg-theme-accent-800 data-[state=active]:shadow-sm",
rounded: "!py-1 !px-3 bg-transparent",
},
},
defaultVariants: {
Expand All @@ -68,58 +67,64 @@ const tabsTriggerVariants = cva("", {
export interface TabsTriggerProps
extends React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>,
VariantProps<typeof tabsTriggerVariants> {}
const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
TabsTriggerProps
>(({ className, variant, children, ...props }, ref) => {
const triggerRef = React.useRef(null)
React.useImperativeHandle(ref, () => triggerRef.current!, [ref])
const TabsTrigger = React.forwardRef<HTMLDivElement, TabsTriggerProps>(
({ className, variant, children, ...props }, ref) => {
const triggerRef = React.useRef<HTMLDivElement>(null)
React.useImperativeHandle(ref, () => triggerRef.current!, [])

const [isSelect, setIsSelect] = React.useState(false)
const id = React.useContext(TabsIdContext)
const layoutId = `tab-selected-underline-${id}`
React.useLayoutEffect(() => {
if (!triggerRef.current) return
const [isSelect, setIsSelect] = React.useState(false)
const id = React.useContext(TabsIdContext)
const layoutId = `tab-selected-underline-${id}`
React.useLayoutEffect(() => {
if (!triggerRef.current) return

const trigger = triggerRef.current as HTMLElement
const trigger = triggerRef.current as HTMLElement

const isSelect = trigger.dataset.state === "active"
setIsSelect(isSelect)
const ob = new MutationObserver(() => {
const isSelect = trigger.dataset.state === "active"
setIsSelect(isSelect)
})
ob.observe(trigger, {
attributes: true,
attributeFilter: ["data-state"],
})
const ob = new MutationObserver(() => {
const isSelect = trigger.dataset.state === "active"
setIsSelect(isSelect)
})
ob.observe(trigger, {
attributes: true,
attributeFilter: ["data-state"],
})

return () => {
ob.disconnect()
}
}, [])
return () => {
ob.disconnect()
}
}, [])

return (
<TabsPrimitive.Trigger
ref={triggerRef}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap px-3 text-sm font-medium ring-offset-background transition-all disabled:pointer-events-none disabled:opacity-50 data-[state=active]:text-theme-foreground",
"relative",
tabsTriggerVariants({ variant }),
className,
)}
{...props}
>
{children}
{isSelect && (
<m.span
layoutId={layoutId}
className="absolute -bottom-1 h-0.5 w-[calc(100%-16px)] rounded bg-accent"
/>
)}
</TabsPrimitive.Trigger>
)
})
return (
<TabsPrimitive.Trigger
ref={triggerRef as any}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap px-3 text-sm font-medium ring-offset-background transition-all disabled:pointer-events-none disabled:opacity-50 data-[state=active]:text-theme-foreground",
"group relative z-[1]",
tabsTriggerVariants({ variant }),
// !isSelect &&
// "hover:before:bg-theme-item-hover before:content-[''] before:pointer-events-none before:absolute before:inset-y-0 before:inset-x-1 before:duration-200 before:opacity-60 before:rounded-lg",
// className,
)}
{...props}
>
{children}
{isSelect && (
<m.span
layoutId={layoutId}
className={cn(
"absolute",
variant === "rounded"
? "inset-0 z-[-1] rounded-lg bg-muted duration-200 group-hover:bg-theme-item-hover"
: "-bottom-1 h-0.5 w-[calc(100%-16px)] rounded bg-accent",
)}
/>
)}
</TabsPrimitive.Trigger>
)
},
)
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName

const TabsContent = React.forwardRef<
Expand Down
3 changes: 0 additions & 3 deletions apps/renderer/src/constants/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ export const ROUTE_FEED_IN_FOLDER = "folder-"
export const ROUTE_FEED_IN_LIST = "list-"
export const ROUTE_FEED_IN_INBOX = "inbox-"

export const DAILY_CLAIM_AMOUNT = "20"
export const INVITATION_PRICE = "100"

export const INBOX_PREFIX_ID = "inbox-"
2 changes: 1 addition & 1 deletion apps/renderer/src/constants/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type React from "react"
import type * as React from "react"

import { FeedViewType } from "~/lib/enum"

Expand Down
39 changes: 0 additions & 39 deletions apps/renderer/src/hooks/biz/useAb.ts

This file was deleted.

9 changes: 1 addition & 8 deletions apps/renderer/src/initialize/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { TrackProperties } from "@openpanel/web"
import { getGeneralSettings } from "~/atoms/settings/general"

import { op } from "./op"
import { initPostHog } from "./posthog"

declare global {
interface Window {
Expand All @@ -15,8 +14,6 @@ declare global {
}
}
export const initAnalytics = () => {
// TODO remove this
initPostHog()
if (env.VITE_OPENPANEL_CLIENT_ID === undefined) return

op.setGlobalProperties({
Expand All @@ -28,17 +25,13 @@ export const initAnalytics = () => {
window.analytics = {
reset: () => {
// op.clear()

// TODO remove this if op ready
window.posthog?.reset()
},
capture(event_name: string, properties?: TrackProperties | null) {
if (import.meta.env.DEV) return
if (!getGeneralSettings().sendAnonymousData) {
return
}
// TODO remove this if op ready
window.posthog?.capture(event_name, properties as TrackProperties)

op.track(event_name, properties as TrackProperties)
},
}
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/initialize/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { env } from "@follow/shared/env"
import { OpenPanel } from "@openpanel/web"

export const op = new OpenPanel({
clientId: env.VITE_OPENPANEL_CLIENT_ID,
clientId: env.VITE_OPENPANEL_CLIENT_ID ?? "",
trackScreenViews: true,
trackOutgoingLinks: true,
trackAttributes: true,
Expand Down
51 changes: 0 additions & 51 deletions apps/renderer/src/initialize/posthog.ts

This file was deleted.

37 changes: 37 additions & 0 deletions apps/renderer/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { memoize } from "lodash-es"
import { twMerge } from "tailwind-merge"
import { parse } from "tldts"

import { getServerConfigs } from "~/atoms/server-configs"
import type { MediaModel } from "~/models"
import type { RSSHubRoute } from "~/modules/discover/types"

Expand Down Expand Up @@ -286,3 +287,39 @@ export const filterSmallMedia = (media: MediaModel) => {
(m) => !(m.type === "photo" && m.width && m.width < 65 && m.height && m.height < 65),
)
}

export const getLevelMultiplier = (level: number) => {
if (level === 0) {
return 0.1
}
const serverConfigs = getServerConfigs()
if (!serverConfigs) {
return 1
}
const level1Range = serverConfigs?.LEVEL_PERCENTAGES[3] - serverConfigs?.LEVEL_PERCENTAGES[2]
const percentageIndex = serverConfigs.LEVEL_PERCENTAGES.length - level
let levelCurrentRange
if (percentageIndex - 1 < 0) {
levelCurrentRange = serverConfigs?.LEVEL_PERCENTAGES[percentageIndex]
} else {
levelCurrentRange =
serverConfigs?.LEVEL_PERCENTAGES[percentageIndex] -
serverConfigs?.LEVEL_PERCENTAGES[percentageIndex - 1]
}
const rangeMultiplier = levelCurrentRange / level1Range

const poolMultiplier =
serverConfigs?.DAILY_POWER_PERCENTAGES[level] / serverConfigs?.DAILY_POWER_PERCENTAGES[1]

return (poolMultiplier / rangeMultiplier).toFixed(0)
}

export const getBlockchainExplorerUrl = () => {
const serverConfigs = getServerConfigs()

if (serverConfigs?.IS_RSS3_TESTNET) {
return `https://scan.testnet.rss3.io`
} else {
return `https://scan.rss3.io`
}
}
2 changes: 2 additions & 0 deletions apps/renderer/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ export type ActionsInput = {
export const TransactionTypes = ["mint", "purchase", "tip", "withdraw"] as const

export type WalletModel = ExtractBizResponse<typeof apiClient.wallets.$get>["data"][number]

export type ServerConfigs = ExtractBizResponse<typeof apiClient.status.configs.$get>["data"]
1 change: 0 additions & 1 deletion apps/renderer/src/modules/claim/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const useFeedClaimModal = ({ feedId }: { feedId?: string }) => {
present({
title: t("feed_claim_modal.title"),
content: () => createElement(FeedClaimModalContent, { feedId }),
modalClassName: "!h-auto !max-h-screen",
})
}, [feedId, present])
}
Loading

0 comments on commit 5084de9

Please sign in to comment.