Skip to content

Commit

Permalink
DashBoard组件相关
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Nov 21, 2024
1 parent 762c9e9 commit d2f97f7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
18 changes: 4 additions & 14 deletions components/ui/dashboard/DashboardBody.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'
import { UserProfile } from '@clerk/nextjs'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import DashboardUser from './DashboardUser'

const DashboardMenuList = dynamic(() => import('./DashboardMenuList'))
const DashboardItemMembership = dynamic(
Expand All @@ -25,21 +25,11 @@ export default function DashboardBody() {
<div className='side-tabs w-full md:w-72'>
<DashboardMenuList />
</div>
{/* 控制台右侧内容 */}
<div className='main-content-wrapper w-full'>
{basePath === '/dashboard' && <DashboardItemHome />}
{(basePath === '/dashboard/user-profile' ||
basePath === '/dashboard/user-profile/security') && (
<UserProfile
appearance={{
elements: {
cardBox: 'w-full',
rootBox: 'w-full'
}
}}
className='bg-blue-300'
routing='path'
path='/dashboard/user-profile'
/>
{basePath?.indexOf('/dashboard/user-profile') === 0 && (
<DashboardUser />
)}
{basePath === '/dashboard/balance' && <DashboardItemBalance />}
{basePath === '/dashboard/membership' && <DashboardItemMembership />}
Expand Down
11 changes: 3 additions & 8 deletions components/ui/dashboard/DashboardHeader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import LazyImage from '@/components/LazyImage'
import { useGlobal } from '@/lib/global'
import formatDate from '@/lib/utils/formatDate'
import { SignOutButton } from '@clerk/nextjs'
import Link from 'next/link'
import DashboardSignOutButton from './DashboardSignOutButton'

/**
* 仪表盘页头
* @returns
Expand Down Expand Up @@ -39,13 +40,7 @@ export default function DashboardHeader() {

{/* 登出按钮 */}
<div className='flex items-center'>
<SignOutButton redirectUrl='/'>
<button className='text-white bg-gray-800 hover:bg-gray-900 hover:ring-4 hover:ring-gray-300 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700'>
<span className='text-nowrap'>
<i className='fas fa-right-from-bracket' /> Sign Out
</span>
</button>
</SignOutButton>
<DashboardSignOutButton />
</div>
</div>
</>
Expand Down
20 changes: 20 additions & 0 deletions components/ui/dashboard/DashboardSignOutButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SignOutButton } from '@clerk/nextjs'
/**
* 控制台登出按钮
* @returns
*/
export default function DashboardSignOutButton() {
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
if (!enableClerk) {
return null
}
return (
<SignOutButton redirectUrl='/'>
<button className='text-white bg-gray-800 hover:bg-gray-900 hover:ring-4 hover:ring-gray-300 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700'>
<span className='text-nowrap'>
<i className='fas fa-right-from-bracket' /> Sign Out
</span>
</button>
</SignOutButton>
)
}
24 changes: 24 additions & 0 deletions components/ui/dashboard/DashboardUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UserProfile } from '@clerk/nextjs'
/**
* 控制台用户账号面板
* @returns
*/
export default function DashboardUser() {
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
if (!enableClerk) {
return null
}
return (
<UserProfile
appearance={{
elements: {
cardBox: 'w-full',
rootBox: 'w-full'
}
}}
className='bg-blue-300'
routing='path'
path='/dashboard/user-profile'
/>
)
}
6 changes: 4 additions & 2 deletions lib/cache/cache_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import MemoryCache from './memory_cache'
export async function getDataFromCache(key, force) {
if (BLOG.ENABLE_CACHE || force) {
const dataFromCache = await getApi().getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
if (!dataFromCache || JSON.stringify(dataFromCache) === '[]') {
return null
}
return getApi().getCache(key)
// console.trace('[API-->>缓存]:', key, dataFromCache)
return dataFromCache
} else {
return null
}
Expand All @@ -23,6 +24,7 @@ export async function setDataToCache(key, data) {
if (!data) {
return
}
// console.trace('[API-->>缓存写入]:', key)
await getApi().setCache(key, data)
}

Expand Down

0 comments on commit d2f97f7

Please sign in to comment.