Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

perf(reactions): add external click detection to close reaction picker, and other optimizations

HoshinoSuzumidc39e0318f6a
diff --git a/app/components/photo/ReactionPicker.vue b/app/components/photo/ReactionPicker.vue
index f55a85d8..d46da9e7 100644
--- a/app/components/photo/ReactionPicker.vue
+++ b/app/components/photo/ReactionPicker.vue
@@ -20,6 +20,16 @@ const emit = defineEmits<{
close: []
}>()
+// 用于检测点击外部
+const pickerRef = ref<HTMLElement | null>(null)
+
+// 点击外部时关闭
+onClickOutside(pickerRef, () => {
+ if (props.isOpen) {
+ emit('close')
+ }
+})
+
// 可用的表态选项
const reactions = computed<Reaction[]>(() => [
{ id: 'like', iconName: 'fluent-emoji-flat:thumbs-up', label: 'like', count: props.reactionCounts?.like || 0 },
@@ -50,6 +60,7 @@ const handleSelect = (id: string) => {
<AnimatePresence>
<motion.div
v-if="isOpen"
+ ref="pickerRef"
:initial="{ opacity: 0, scale: 0.9, y: 10 }"
:animate="{ opacity: 1, scale: 1, y: 0 }"
:exit="{ opacity: 0, scale: 0.9, y: 10 }"
@@ -112,6 +123,7 @@ const handleSelect = (id: string) => {
<Icon
:name="reaction.iconName"
class="text-[28px] select-none"
+ mode="svg"
/>
<!-- 数量徽章 - 右上角 -->
diff --git a/app/components/photo/Viewer.vue b/app/components/photo/Viewer.vue
index 7ec9bd88..5f60587c 100644
--- a/app/components/photo/Viewer.vue
+++ b/app/components/photo/Viewer.vue
@@ -788,7 +788,7 @@ const swiperModules = [Navigation, Keyboard, Virtual]
damping: 20,
delay: 0.1
}"
- class="absolute bottom-6 right-6 z-20"
+ class="absolute bottom-4 right-4 z-20"
>
<div class="relative">
<!-- 表态选择器 -->
diff --git a/package.json b/package.json
index 02f13b85..fd319bfd 100644
--- a/package.json
+++ b/package.json
@@ -76,6 +76,7 @@
"packageManager": "[email protected]+sha512.1f79bc245a66eb0b07c5d4d83131240774642caaa86ef7d0434ab47c0d16f66b04e21e0c086eb61e62c77efc4d7f7ec071afad3796af64892fae66509173893a",
"devDependencies": {
"@iconify-json/carbon": "^1.2.13",
+ "@iconify-json/fluent-emoji-flat": "^1.2.5",
"@iconify-json/lucide": "^1.2.68",
"@iconify-json/material-symbols": "^1.2.33",
"@iconify-json/mdi": "^1.2.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 532e504a..e55e1c50 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -150,6 +150,9 @@ importers:
'@iconify-json/carbon':
specifier: ^1.2.13
version: 1.2.13
+ '@iconify-json/fluent-emoji-flat':
+ specifier: ^1.2.5
+ version: 1.2.5
'@iconify-json/lucide':
specifier: ^1.2.68
version: 1.2.68
@@ -1006,6 +1009,9 @@ packages:
'@iconify-json/[email protected]':
resolution: {integrity: sha512-vXrFFKkfYaZSwf4WfnRQJQMnpEzxlPlupwZZlS1WvOAuNnWahsUudHycaMpoBzDqBfniH4KQ2b5qnw0VMKoJug==}
+ '@iconify-json/[email protected]':
+ resolution: {integrity: sha512-5ShoOHJ0ezYEIMfp2zvbRiZpL1Af8Prg5v9pElaIQhfqwbyD57pzrp70g/rK2EjigajBq9/cPrJXh224HaP3TQ==}
+
'@iconify-json/[email protected]':
resolution: {integrity: sha512-lR5xNJdn2CT0iR7lM25G4SewBO4G2hbr3fTWOc3AE9BspflEcneh02E3l9TBaCU/JOHozTJevWLrxBGypD7Tng==}
@@ -8587,6 +8593,10 @@ snapshots:
dependencies:
'@iconify/types': 2.0.0
+ '@iconify-json/[email protected]':
+ dependencies:
+ '@iconify/types': 2.0.0
+
'@iconify-json/[email protected]':
dependencies:
'@iconify/types': 2.0.0
diff --git a/server/api/photos/[id]/reactions.ts b/server/api/photos/[id]/reactions.ts
index befd3328..797a361c 100644
--- a/server/api/photos/[id]/reactions.ts
+++ b/server/api/photos/[id]/reactions.ts
@@ -1,5 +1,5 @@
import type { H3Event } from 'h3'
-import { useDB, tables, eq, and, sql } from '~~/server/utils/db'
+import { eq, and, sql } from 'drizzle-orm'
const REACTION_TYPES = ['like', 'love', 'amazing', 'funny', 'wow', 'sad', 'fire', 'sparkle'] as const
const RATE_LIMIT_WINDOW = 60 * 1000 // 1分钟
diff --git a/server/api/photos/reactions.get.ts b/server/api/photos/reactions.get.ts
index 06c9c9e9..bb5106fc 100644
--- a/server/api/photos/reactions.get.ts
+++ b/server/api/photos/reactions.get.ts
@@ -1,4 +1,4 @@
-import { useDB, tables, sql, inArray } from '~~/server/utils/db'
+import { sql, inArray } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
@@ -21,11 +21,11 @@ export default defineEventHandler(async (event) => {
const db = useDB()
// 获取所有照片的表态统计
- const reactions = await db
+ const reactions = db
.select({
photoId: tables.photoReactions.photoId,
reactionType: tables.photoReactions.reactionType,
- count: sql<number>`count(*)`,
+ count: sql<number> `count(*)`,
})
.from(tables.photoReactions)
.where(inArray(tables.photoReactions.photoId, ids as string[]))
diff --git a/server/utils/db.ts b/server/utils/db.ts
index a1fc0af5..e91c4c36 100644
--- a/server/utils/db.ts
+++ b/server/utils/db.ts
@@ -3,7 +3,6 @@ import { drizzle } from 'drizzle-orm/better-sqlite3'
import Database from 'better-sqlite3'
import * as schema from '../database/schema'
-export { sql, eq, and, or, inArray } from 'drizzle-orm'
export const tables = schema
@@ -44,3 +43,5 @@ export type Photo = typeof schema.photos.$inferSelect
export type PipelineQueueItem = typeof schema.pipelineQueue.$inferSelect
export type NewPipelineQueueItem = typeof schema.pipelineQueue.$inferInsert
+
+export type PhotoReaction = typeof schema.photoReactions.$inferSelect