Skip to content

Commit

Permalink
feat: go admin and editing
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 7, 2023
1 parent 16b3866 commit c851c73
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/app/(page-detail)/[slug]/pageExtra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { PropsWithChildren } from 'react'

import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks'
import { Markdown } from '~/components/ui/markdown'
import { GoToAdminEditingButton } from '~/components/widgets/shared/GoToAdminEditingButton'
import { noopArr } from '~/lib/noop'
import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider'
import { useCurrentPageDataSelector } from '~/providers/page/CurrentPageDataProvider'
Expand Down Expand Up @@ -63,10 +64,18 @@ export const PageSubTitle = () => {
}
export const PageTitle = () => {
const title = useCurrentPageDataSelector((data) => data?.title)
const id = useCurrentPageDataSelector((data) => data?.id)
return (
<h1 className="text-center lg:text-left">
<Balancer>{title}</Balancer>
</h1>
<>
<h1 className="text-center lg:text-left">
<Balancer>{title}</Balancer>
</h1>
<GoToAdminEditingButton
id={id!}
type="pages"
className="absolute -top-6 right-0"
/>
</>
)
}
export const HeaderMetaInfoSetting = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/friends/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-no-target-blank */
'use client'

import { useQuery } from '@tanstack/react-query'
Expand Down Expand Up @@ -150,7 +151,6 @@ const Card: FC<{ link: LinkModel }> = ({ link }) => {
layoutId={link.id}
href={link.url}
target="_blank"
rel="noreferrer"
role="link"
aria-label={`Go to ${link.name}'s website`}
className="relative flex flex-col items-center justify-center"
Expand Down Expand Up @@ -183,7 +183,7 @@ const FavoriteSection: FC<FriendSectionProps> = ({ data }) => {
{data.map((link) => {
return (
<li key={link.id}>
<a href={link.url} target="_blank" rel="noreferrer">
<a href={link.url} target="_blank">
{link.name}
</a>
<span className="meta">{link.description || ''}</span>
Expand Down
13 changes: 12 additions & 1 deletion src/app/notes/[id]/pageExtra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MdiClockOutline } from '~/components/icons/clock'
import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks'
import { FloatPopover } from '~/components/ui/float-popover'
import { Markdown } from '~/components/ui/markdown'
import { GoToAdminEditingButton } from '~/components/widgets/shared/GoToAdminEditingButton'
import { parseDate } from '~/lib/datetime'
import { noopArr } from '~/lib/noop'
import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider'
Expand All @@ -22,9 +23,19 @@ import styles from './page.module.css'

export const NoteTitle = () => {
const title = useCurrentNoteDataSelector((data) => data?.data.title)
const id = useCurrentNoteDataSelector((data) => data?.data.id)

if (!title) return null
return (
<h1 className="mt-8 text-left font-bold text-base-content/95">{title}</h1>
<>
<h1 className="mt-8 text-left font-bold text-base-content/95">{title}</h1>

<GoToAdminEditingButton
type="notes"
id={id!}
className="absolute -top-6 right-0"
/>
</>
)
}

Expand Down
6 changes: 6 additions & 0 deletions src/app/posts/(post-detail)/[category]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PostCopyright } from '~/components/widgets/post/PostCopyright'
import { PostOutdate } from '~/components/widgets/post/PostOutdate'
import { PostRelated } from '~/components/widgets/post/PostRelated'
import { ArticleRightAside } from '~/components/widgets/shared/ArticleRightAside'
import { GoToAdminEditingButton } from '~/components/widgets/shared/GoToAdminEditingButton'
import { ReadIndicatorForMobile } from '~/components/widgets/shared/ReadIndicator'
import { SubscribeBell } from '~/components/widgets/subscribe/SubscribeBell'
import { XLogInfoForPost, XLogSummaryForPost } from '~/components/widgets/xlog'
Expand Down Expand Up @@ -45,6 +46,11 @@ const PostPage = () => {
<h1 className="text-center">
<Balancer>{title}</Balancer>
</h1>
<GoToAdminEditingButton
id={id!}
type="posts"
className="absolute -top-6 right-0"
/>

<PostMetaBarInternal className="mb-8 justify-center" />

Expand Down
10 changes: 10 additions & 0 deletions src/atoms/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ export const useAppUrl = () => {
...url,
}
}

export const useResolveAdminUrl = () => {
const { adminUrl } = useAppUrl()
return (path: string) => {
if (!adminUrl) {
return ''
}
return adminUrl.replace(/\/$/, '').concat(path || '')
}
}
2 changes: 1 addition & 1 deletion src/components/ui/link-card/LinkCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@apply cursor-pointer border font-sans no-underline;
@apply [&_*]:!not-italic;
@apply border border-slate-100 bg-gray-100/80 dark:border-neutral-700 dark:bg-neutral-800;
@apply border border-slate-200/80 bg-gray-100/80 dark:border-neutral-700 dark:bg-zinc-800;
@apply transition-colors duration-200;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/markdown/parsers/mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const MentionRule: MarkdownToJSX.Rule = {
target="_blank"
rel="noreferrer nofollow"
href={`${urlPrefix}${name}`}
className="no-underline"
className="underline-offset-2"
>
{displayName || name}
</a>
Expand Down
31 changes: 31 additions & 0 deletions src/components/widgets/shared/GoToAdminEditingButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client'

import { useIsLogged, useResolveAdminUrl } from '~/atoms'
import { clsxm } from '~/lib/helper'

interface Props {
type: 'notes' | 'pages' | 'posts'
id: string
}
export const GoToAdminEditingButton: Component<Props> = (props) => {
const isLogin = useIsLogged()
const resolveAdminUrl = useResolveAdminUrl()
const { id, type, className } = props
if (!isLogin) return null

return (
<a
href={resolveAdminUrl(`#/${type}/edit?id=${id}`)}
data-hide-print
target="_blank"
className={clsxm(
'flex h-8 w-8 rounded-full text-accent no-underline opacity-80 ring-1 ring-slate-200 duration-200 center hover:opacity-100 dark:ring-neutral-800',
className,
)}
rel="noreferrer"
>
<i className="icon-[mingcute--quill-pen-line]" />
<span className="sr-only">编辑</span>
</a>
)
}

1 comment on commit c851c73

@vercel
Copy link

@vercel vercel bot commented on c851c73 Jul 7, 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-git-main-innei.vercel.app
springtide.vercel.app
innei.in
shiro-innei.vercel.app

Please sign in to comment.