Skip to content

Commit da4f3e9

Browse files
committed
feat: integrate with backend
1 parent 8881d62 commit da4f3e9

13 files changed

Lines changed: 174 additions & 27 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@fontsource-variable/inter": "^5.2.8",
1717
"@fontsource/maple-mono": "^5.2.5",
1818
"@iconify-json/simple-icons": "^1.2.54",
19+
"@nanostores/react": "^1.0.0",
1920
"@radix-ui/react-accordion": "^1.2.12",
2021
"@radix-ui/react-avatar": "^1.1.10",
2122
"@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -30,6 +31,7 @@
3031
"dayjs": "^1.11.18",
3132
"lucide-react": "^0.545.0",
3233
"medium-zoom": "^1.1.0",
34+
"nanostores": "^1.0.1",
3335
"react": "^19.2.0",
3436
"react-dom": "^19.2.0",
3537
"rehype-autolink-headings": "^7.1.0",

pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Header.astro

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import { fade } from 'astro:transitions'
3-
import BlogAvatar from './common/BlogAvatar.astro'
3+
import HeaderAvatar from './common/HeaderAvatar.astro'
44
import { HeaderActions } from './HeaderActions'
55
---
66

@@ -14,11 +14,10 @@ import { HeaderActions } from './HeaderActions'
1414
class="sticky top-0 z-100 h-16 px-4 bg-background border-b-1 select-none"
1515
transition:name="header"
1616
transition:animate="initial"
17+
transition:persist
1718
>
1819
<div class="h-full max-w-4xl mx-auto flex items-center justify-between">
19-
<a class="block" href="/">
20-
<BlogAvatar size={40} />
21-
</a>
20+
<HeaderAvatar />
2221

2322
<HeaderActions client:load />
2423
</div>

src/components/common/BlogAvatar.astro

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
import { Image } from 'astro:assets'
3+
import { HeaderAvatarActivity } from './HeaderAvatarActivity'
4+
---
5+
6+
<script>
7+
import { onSocketMessage } from '@/utils/socket'
8+
import { $activityIconUrl, $activityMessage } from '@/utils/stores'
9+
10+
let timeout: NodeJS.Timeout | null = null
11+
12+
onSocketMessage((message) => {
13+
if (message.type !== 'activity') return
14+
15+
if (timeout) clearTimeout(timeout)
16+
timeout = setTimeout(() => {
17+
document.querySelector('.activity-icon')?.classList.add('hidden')
18+
}, 30000)
19+
20+
$activityIconUrl.set(message.icon)
21+
$activityMessage.set(message.message)
22+
document.querySelector('.activity-icon')?.classList.remove('hidden')
23+
})
24+
</script>
25+
26+
<div class="relative">
27+
<a href="/">
28+
<Image
29+
class="rounded-full"
30+
src="https://avatars.githubusercontent.com/bsdayo"
31+
alt="@bsdayo"
32+
width={40}
33+
height={40}
34+
loading="eager"
35+
/>
36+
</a>
37+
<HeaderAvatarActivity client:only="react" className="absolute -bottom-1 -right-1 size-5" />
38+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { cn } from '@/lib/utils'
2+
import { HoverCard, HoverCardTrigger, HoverCardContent } from '../ui/hover-card'
3+
import { $activityIconUrl, $activityMessage } from '@/utils/stores'
4+
import { useStore } from '@nanostores/react'
5+
6+
export function HeaderAvatarActivity({ className }: { className?: string }) {
7+
const activityIconUrl = useStore($activityIconUrl)
8+
const activityMessage = useStore($activityMessage)
9+
return (
10+
<HoverCard openDelay={0}>
11+
<HoverCardTrigger asChild>
12+
<img className={cn('activity-icon hidden', className)} src={activityIconUrl} />
13+
</HoverCardTrigger>
14+
<HoverCardContent className="w-fit z-200 text-sm" collisionPadding={16}>
15+
{activityMessage}
16+
</HoverCardContent>
17+
</HoverCard>
18+
)
19+
}

src/components/ui/hover-card.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as React from "react"
2+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
3+
4+
import { cn } from "@/lib/utils"
5+
6+
function HoverCard({
7+
...props
8+
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
9+
return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />
10+
}
11+
12+
function HoverCardTrigger({
13+
...props
14+
}: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
15+
return (
16+
<HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
17+
)
18+
}
19+
20+
function HoverCardContent({
21+
className,
22+
align = "center",
23+
sideOffset = 4,
24+
...props
25+
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
26+
return (
27+
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
28+
<HoverCardPrimitive.Content
29+
data-slot="hover-card-content"
30+
align={align}
31+
sideOffset={sideOffset}
32+
className={cn(
33+
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
34+
className
35+
)}
36+
{...props}
37+
/>
38+
</HoverCardPrimitive.Portal>
39+
)
40+
}
41+
42+
export { HoverCard, HoverCardTrigger, HoverCardContent }

src/layouts/MainLayout.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
import '@/styles/global.css'
33
import { ClientRouter } from 'astro:transitions'
4+
import siteConfig from '@/site.config'
45
56
interface Props {
67
title?: string
78
}
89
9-
const baseTitle = "bsdayo's blog w/ Astro"
10-
const title = Astro.props.title ? `${Astro.props.title} | ${baseTitle}` : baseTitle
10+
const title = Astro.props.title ? `${Astro.props.title} | ${siteConfig.title}` : siteConfig.title
1111
---
1212

1313
<script is:inline>

src/pages/index.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
layout: '@/layouts/ContentLayout.astro'
33
---
44

5-
import BlogAvatar from '@/components/common/BlogAvatar.astro'
5+
import { Image } from 'astro:assets'
66

7-
<BlogAvatar size={256} />
7+
<Image
8+
class="rounded-full"
9+
src="https://avatars.githubusercontent.com/bsdayo"
10+
alt="@bsdayo"
11+
width={200}
12+
height={200}
13+
loading="eager"
14+
/>
815

916
# bsdayo
1017

src/site.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ShikiConfig } from 'astro'
22

33
export default {
4+
title: "bsdayo's blog",
45
site: 'https://bsdayo.moe',
6+
backend: import.meta.env.DEV ? 'ws://localhost:8123' : 'wss://blog-backend.bsdayo.moe',
57
shikiThemes: {
68
light: 'catppuccin-latte',
79
dark: 'catppuccin-mocha',

0 commit comments

Comments
 (0)