Skip to content

Commit

Permalink
fix: category slug reactive closes #294
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Feb 13, 2024
1 parent c009425 commit c6e8d69
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/components/layout/header/internal/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const ActivityIcon = memo(() => {
}
setActivityProcessInfo({
name: data.processInfo?.name || data.processName,
iconUrl: data.processInfo?.iconUrl,
iconBase64: data.processInfo?.iconBase64,
description: data.processInfo?.description,
})
Expand Down Expand Up @@ -203,7 +204,11 @@ const TriggerComponent = memo<{
const isBuiltIn = !!appIcon[processName]

const src =
!isBuiltIn && icon ? icon : `${CND_DOMAIN}/apps/${appIcon[processName]}.png`
!isBuiltIn && icon
? icon
: isBuiltIn
? `${CND_DOMAIN}/apps/${appIcon[processName]}.png`
: ''

const className = clsx('pointer-events-none select-none', {
'rounded-md': !isBuiltIn,
Expand All @@ -214,7 +219,7 @@ const TriggerComponent = memo<{
<Image
width={32}
height={32}
src={error ? ErrorFallback : src}
src={error ? ErrorFallback : src || ErrorFallback}
alt={processName}
priority
fetchPriority="low"
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/dashboard/home/Shiju.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ShiJu = () => {
if (!origin) return null
return (
<FloatPopover triggerElement={<span>{data?.shiju}</span>}>
<div className="text-center">
<div className="max-w-[800px] text-center">
<h3 className="sticky top-0 py-2 text-2xl font-medium">
{origin.title}
</h3>
Expand Down
19 changes: 15 additions & 4 deletions src/components/modules/dashboard/post-editing/SlugInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import { useEffect, useRef } from 'react'
import { useEffect, useMemo, useRef } from 'react'
import type { CategoryModel } from '@mx-space/api-client'

import { adminQueries } from '~/queries/definition'

Expand All @@ -22,14 +23,24 @@ export const SlugInput = () => {
setCategoryId(category.id)
}
}, [category, categoryId, setCategoryId])
const categoryIdMap: Record<string, CategoryModel> = useMemo(() => {
if (!categories) return {}
return categories.data.reduce(
(acc, category) => ({
...acc,
[category.id]: category,
}),
{},
)
}, [categories])

const isLoading = !category
return (
<>
{isLoading ? (
<div className="h-2 w-[120px] animate-pulse bg-white " />
{isLoading || !categoryId ? (
<div className="h-2 w-[120px] animate-pulse bg-white" />
) : (
<label className="text-base-content">{`${webUrl}/posts/${category?.slug}/`}</label>
<label className="text-base-content">{`${webUrl}/posts/${categoryIdMap?.[categoryId]?.slug}/`}</label>
)}

<div className="relative ml-1 inline-flex min-w-[2rem] items-center overflow-hidden rounded-md bg-white py-1 dark:bg-zinc-900 [&_*]:leading-4">
Expand Down

0 comments on commit c6e8d69

Please sign in to comment.