Skip to content

Commit

Permalink
feat: support activity config
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 16, 2023
1 parent 1fed006 commit 5b5cb30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/app/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export interface TemplateItem {
export interface Module {
donate: Donate
bilibili: Bilibili
activity: {
enable: boolean
endpoint: string
}
}
export interface Donate {
enable: boolean
Expand Down
19 changes: 12 additions & 7 deletions src/components/layout/header/internal/Activity.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useQuery } from '@tanstack/react-query'
import React, { memo, useEffect, useMemo, useState } from 'react'
import React, { memo, useEffect, useMemo } from 'react'
import { AnimatePresence, m } from 'framer-motion'
import Image from 'next/image'
import type { RequestError } from '@mx-space/api-client'
Expand All @@ -18,7 +18,10 @@ import { TrackerAction } from '~/constants/tracker'
import useDebounceValue from '~/hooks/common/use-debounce-value'
import { usePageIsActive } from '~/hooks/common/use-is-active'
import { apiClient } from '~/lib/request'
import { useAggregationSelector } from '~/providers/root/aggregation-data-provider'
import {
useAggregationSelector,
useAppConfigSelector,
} from '~/providers/root/aggregation-data-provider'

// autocorrect: false
const appDescrption = {
Expand Down Expand Up @@ -73,15 +76,18 @@ const appLabels: { [app: string]: string } = {
}
// autocorrect: true
export const Activity = memo(() => {
const [isEnabled, setIsEnabled] = useState(true)

const activityConfig = useAppConfigSelector(
(config) => config.module.activity,
)
const { enable = false, endpoint = '/fn/ps/update' } = activityConfig || {}
const activity = useActivity()

const isPageActive = usePageIsActive()
const { data } = useQuery(
['activity'],
async () => {
return await apiClient.proxy.fn.ps.update
return await apiClient
.proxy(endpoint)
.post<{
processName: string
mediaInfo?: {
Expand All @@ -91,7 +97,6 @@ export const Activity = memo(() => {
}>()
.then((res) => res)
.catch((err: RequestError) => {
setIsEnabled(false)
return { processName: '', mediaInfo: undefined }
})
},
Expand All @@ -101,7 +106,7 @@ export const Activity = memo(() => {
retry: false,
refetchOnReconnect: true,
refetchOnWindowFocus: 'always',
enabled: isEnabled && isPageActive,
enabled: enable && isPageActive,
meta: {
persist: false,
},
Expand Down

1 comment on commit 5b5cb30

@vercel
Copy link

@vercel vercel bot commented on 5b5cb30 Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app
innei.in

Please sign in to comment.