feat: 💨

This commit is contained in:
codytseng
2025-09-01 13:40:58 +08:00
parent 1ee3718cab
commit a1285fe44d
18 changed files with 60 additions and 30 deletions

View File

@@ -12,7 +12,7 @@ import { useSecondaryPage } from '@/PageManager'
import { useScreenSize } from '@/providers/ScreenSizeProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider'
import modalManager from '@/services/modal-manager.service' import modalManager from '@/services/modal-manager.service'
import { TProfile, TSearchParams } from '@/types' import { TProfile, TSearchParams } from '@/types'
import { Hash, Notebook, Server, UserRound } from 'lucide-react' import { Hash, Notebook, Search, Server, UserRound } from 'lucide-react'
import { nip19 } from 'nostr-tools' import { nip19 } from 'nostr-tools'
import { import {
forwardRef, forwardRef,
@@ -82,10 +82,6 @@ const SearchBar = forwardRef<
searchInputRef.current?.blur() searchInputRef.current?.blur()
} }
const startSearch = () => {
setSearching(true)
}
const list = useMemo(() => { const list = useMemo(() => {
const search = input.trim() const search = input.trim()
if (!search) return null if (!search) return null
@@ -167,21 +163,19 @@ const SearchBar = forwardRef<
) )
}, [input, debouncedInput, profiles]) }, [input, debouncedInput, profiles])
const showList = useMemo(() => searching && !!list, [searching, list])
useEffect(() => { useEffect(() => {
if (showList) { if (searching) {
modalManager.register(id, () => { modalManager.register(id, () => {
blur() blur()
}) })
} else { } else {
modalManager.unregister(id) modalManager.unregister(id)
} }
}, [showList]) }, [searching])
return ( return (
<div className="relative flex gap-1 items-center h-full w-full"> <div className="relative flex gap-1 items-center h-full w-full">
{showList && ( {searching && (
<> <>
<div <div
className={cn( className={cn(
@@ -193,7 +187,13 @@ const SearchBar = forwardRef<
)} )}
onMouseDown={(e) => e.preventDefault()} onMouseDown={(e) => e.preventDefault()}
> >
<ScrollArea className="h-[60vh]">{list}</ScrollArea> {list ? (
<ScrollArea className="h-[60vh]">{list}</ScrollArea>
) : (
<div className="p-4 text-muted-foreground text-center h-20">
{t('Type searching for people, keywords, or relays')}
</div>
)}
</div> </div>
<div className="fixed inset-0 w-full h-full" onClick={() => blur()} /> <div className="fixed inset-0 w-full h-full" onClick={() => blur()} />
</> </>
@@ -206,7 +206,8 @@ const SearchBar = forwardRef<
)} )}
value={input} value={input}
onChange={(e) => setInput(e.target.value)} onChange={(e) => setInput(e.target.value)}
onFocus={() => startSearch()} onFocus={() => setSearching(true)}
onBlur={() => setSearching(false)}
/> />
</div> </div>
) )
@@ -222,7 +223,7 @@ export type TSearchBarRef = {
function NormalItem({ search, onClick }: { search: string; onClick?: () => void }) { function NormalItem({ search, onClick }: { search: string; onClick?: () => void }) {
return ( return (
<Item onClick={onClick}> <Item onClick={onClick}>
<Notebook className="text-muted-foreground" /> <Search className="text-muted-foreground" />
<div className="font-semibold truncate">{search}</div> <div className="font-semibold truncate">{search}</div>
</Item> </Item>
) )

View File

@@ -41,6 +41,7 @@ const SearchInput = forwardRef<HTMLInputElement, ComponentProps<'input'>>(
<button <button
type="button" type="button"
className="rounded-full bg-foreground/40 hover:bg-foreground transition-opacity size-5 shrink-0 flex flex-col items-center justify-center" className="rounded-full bg-foreground/40 hover:bg-foreground transition-opacity size-5 shrink-0 flex flex-col items-center justify-center"
onMouseDown={(e) => e.preventDefault()}
onClick={() => onChange?.({ target: { value: '' } } as any)} onClick={() => onChange?.({ target: { value: '' } } as any)}
> >
<X className="!size-3 shrink-0 text-background" strokeWidth={4} /> <X className="!size-3 shrink-0 text-background" strokeWidth={4} />

View File

@@ -370,6 +370,8 @@ export default {
'Share something on this Relay': 'شارك شيئاً على هذا الريلاي', 'Share something on this Relay': 'شارك شيئاً على هذا الريلاي',
'Try deleting this note': 'حاول حذف هذه الملاحظة', 'Try deleting this note': 'حاول حذف هذه الملاحظة',
'Deletion request sent to {{count}} relays': 'تم إرسال طلب الحذف إلى {{count}} ريلايات', 'Deletion request sent to {{count}} relays': 'تم إرسال طلب الحذف إلى {{count}} ريلايات',
'Suitable Relays': 'الريلايات المناسبة' 'Suitable Relays': 'الريلايات المناسبة',
'Type searching for people, keywords, or relays':
'اكتب للبحث عن أشخاص، كلمات مفتاحية، أو ريلايات'
} }
} }

View File

@@ -378,6 +378,8 @@ export default {
'Share something on this Relay': 'Teile etwas auf diesem Relay', 'Share something on this Relay': 'Teile etwas auf diesem Relay',
'Try deleting this note': 'Versuche, diese Notiz zu löschen', 'Try deleting this note': 'Versuche, diese Notiz zu löschen',
'Deletion request sent to {{count}} relays': 'Löschanfrage an {{count}} Relays gesendet', 'Deletion request sent to {{count}} relays': 'Löschanfrage an {{count}} Relays gesendet',
'Suitable Relays': 'Geeignete Relays' 'Suitable Relays': 'Geeignete Relays',
'Type searching for people, keywords, or relays':
'Gib ein, um nach Personen, Schlüsselwörtern oder Relays zu suchen'
} }
} }

View File

@@ -369,6 +369,8 @@ export default {
'Share something on this Relay': 'Share something on this Relay', 'Share something on this Relay': 'Share something on this Relay',
'Try deleting this note': 'Try deleting this note', 'Try deleting this note': 'Try deleting this note',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays', 'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays',
'Suitable Relays': 'Suitable Relays' 'Suitable Relays': 'Suitable Relays',
'Type searching for people, keywords, or relays':
'Type searching for people, keywords, or relays'
} }
} }

View File

@@ -375,6 +375,8 @@ export default {
'Try deleting this note': 'Intenta eliminar esta nota', 'Try deleting this note': 'Intenta eliminar esta nota',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'Solicitud de eliminación enviada a {{count}} relés', 'Solicitud de eliminación enviada a {{count}} relés',
'Suitable Relays': 'Relés adecuados' 'Suitable Relays': 'Relés adecuados',
'Type searching for people, keywords, or relays':
'Escribe para buscar personas, palabras clave o relés'
} }
} }

View File

@@ -371,6 +371,8 @@ export default {
'Share something on this Relay': 'در این رله چیزی به اشتراک بگذارید', 'Share something on this Relay': 'در این رله چیزی به اشتراک بگذارید',
'Try deleting this note': 'سعی کنید این یادداشت را حذف کنید', 'Try deleting this note': 'سعی کنید این یادداشت را حذف کنید',
'Deletion request sent to {{count}} relays': 'درخواست حذف به {{count}} رله ارسال شد', 'Deletion request sent to {{count}} relays': 'درخواست حذف به {{count}} رله ارسال شد',
'Suitable Relays': 'رله‌های مناسب' 'Suitable Relays': 'رله‌های مناسب',
'Type searching for people, keywords, or relays':
'برای جستجو افراد، کلمات کلیدی یا رله‌ها تایپ کنید'
} }
} }

View File

@@ -377,6 +377,8 @@ export default {
'Try deleting this note': 'Essayez de supprimer cette note', 'Try deleting this note': 'Essayez de supprimer cette note',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'Demande de suppression envoyée à {{count}} relais', 'Demande de suppression envoyée à {{count}} relais',
'Suitable Relays': 'Relais adaptés' 'Suitable Relays': 'Relais adaptés',
'Type searching for people, keywords, or relays':
'Tapez pour rechercher des personnes, des mots-clés ou des relais'
} }
} }

View File

@@ -375,6 +375,8 @@ export default {
'Try deleting this note': 'Prova a eliminare questa nota', 'Try deleting this note': 'Prova a eliminare questa nota',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'Richiesta di eliminazione inviata a {{count}} relays', 'Richiesta di eliminazione inviata a {{count}} relays',
'Suitable Relays': 'Relays adatti' 'Suitable Relays': 'Relays adatti',
'Type searching for people, keywords, or relays':
'Digita per cercare persone, parole chiave o relays'
} }
} }

View File

@@ -372,6 +372,8 @@ export default {
'Try deleting this note': 'このノートを削除してみてください', 'Try deleting this note': 'このノートを削除してみてください',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'削除リクエストが{{count}}個のリレーに送信されました', '削除リクエストが{{count}}個のリレーに送信されました',
'Suitable Relays': '適切なリレー' 'Suitable Relays': '適切なリレー',
'Type searching for people, keywords, or relays':
'人、キーワード、またはリレーを検索するために入力してください'
} }
} }

View File

@@ -372,6 +372,8 @@ export default {
'Try deleting this note': '이 노트를 삭제해 보세요', 'Try deleting this note': '이 노트를 삭제해 보세요',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'삭제 요청이 {{count}}개의 릴레이로 전송되었습니다', '삭제 요청이 {{count}}개의 릴레이로 전송되었습니다',
'Suitable Relays': '적합한 릴레이' 'Suitable Relays': '적합한 릴레이',
'Type searching for people, keywords, or relays':
'사람, 키워드 또는 릴레이를 검색하려면 입력하세요'
} }
} }

View File

@@ -376,6 +376,8 @@ export default {
'Try deleting this note': 'Spróbuj usunąć ten wpis', 'Try deleting this note': 'Spróbuj usunąć ten wpis',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'Żądanie usunięcia wysłane do {{count}} przekaźników', 'Żądanie usunięcia wysłane do {{count}} przekaźników',
'Suitable Relays': 'Odpowiednie przekaźniki' 'Suitable Relays': 'Odpowiednie przekaźniki',
'Type searching for people, keywords, or relays':
'Wpisz, aby wyszukać osoby, słowa kluczowe lub przekaźniki'
} }
} }

View File

@@ -372,6 +372,8 @@ export default {
'Share something on this Relay': 'Compartilhe algo neste Relay', 'Share something on this Relay': 'Compartilhe algo neste Relay',
'Try deleting this note': 'Solicitar exclusão desta nota', 'Try deleting this note': 'Solicitar exclusão desta nota',
'Deletion request sent to {{count}} relays': 'Pedido de exclusão enviado para {{count}} relays', 'Deletion request sent to {{count}} relays': 'Pedido de exclusão enviado para {{count}} relays',
'Suitable Relays': 'Relays adequados' 'Suitable Relays': 'Relays adequados',
'Type searching for people, keywords, or relays':
'Digite para buscar pessoas, palavras-chave ou relays'
} }
} }

View File

@@ -375,6 +375,8 @@ export default {
'Try deleting this note': 'Tente eliminar esta nota', 'Try deleting this note': 'Tente eliminar esta nota',
'Deletion request sent to {{count}} relays': 'Deletion request sent to {{count}} relays':
'Pedido de eliminação enviado para {{count}} relays', 'Pedido de eliminação enviado para {{count}} relays',
'Suitable Relays': 'Relays adequados' 'Suitable Relays': 'Relays adequados',
'Type searching for people, keywords, or relays':
'Digite para buscar pessoas, palavras-chave ou relays'
} }
} }

View File

@@ -375,6 +375,8 @@ export default {
'Share something on this Relay': 'Поделиться чем-то на этом релее', 'Share something on this Relay': 'Поделиться чем-то на этом релее',
'Try deleting this note': 'Попробуйте удалить эту заметку', 'Try deleting this note': 'Попробуйте удалить эту заметку',
'Deletion request sent to {{count}} relays': 'Запрос на удаление отправлен на {{count}} релеев', 'Deletion request sent to {{count}} relays': 'Запрос на удаление отправлен на {{count}} релеев',
'Suitable Relays': 'Подходящие релея' 'Suitable Relays': 'Подходящие релея',
'Type searching for people, keywords, or relays':
'Начните ввод для поиска людей, ключевых слов или релеев'
} }
} }

View File

@@ -368,6 +368,7 @@ export default {
'Share something on this Relay': 'แชร์บางอย่างบนรีเลย์นี้', 'Share something on this Relay': 'แชร์บางอย่างบนรีเลย์นี้',
'Try deleting this note': 'ลองลบโน้ตนี้ดู', 'Try deleting this note': 'ลองลบโน้ตนี้ดู',
'Deletion request sent to {{count}} relays': 'คำขอลบถูกส่งไปยังรีเลย์ {{count}} รายการ', 'Deletion request sent to {{count}} relays': 'คำขอลบถูกส่งไปยังรีเลย์ {{count}} รายการ',
'Suitable Relays': 'รีเลย์ที่เหมาะสม' 'Suitable Relays': 'รีเลย์ที่เหมาะสม',
'Type searching for people, keywords, or relays': 'พิมพ์เพื่อค้นหาผู้คน คีย์เวิร์ด หรือรีเลย์'
} }
} }

View File

@@ -366,6 +366,7 @@ export default {
'Share something on this Relay': '在此服务器上分享点什么', 'Share something on this Relay': '在此服务器上分享点什么',
'Try deleting this note': '尝试删除此笔记', 'Try deleting this note': '尝试删除此笔记',
'Deletion request sent to {{count}} relays': '删除请求已发送到 {{count}} 个服务器', 'Deletion request sent to {{count}} relays': '删除请求已发送到 {{count}} 个服务器',
'Suitable Relays': '适合的服务器' 'Suitable Relays': '适合的服务器',
'Type searching for people, keywords, or relays': '输入以搜索用户、关键词或服务器'
} }
} }

View File

@@ -13,10 +13,10 @@ const SearchPage = forwardRef((_, ref) => {
const isActive = useMemo(() => current === 'search' && display, [current, display]) const isActive = useMemo(() => current === 'search' && display, [current, display])
useEffect(() => { useEffect(() => {
if (isActive) { if (isActive && !searchParams) {
searchBarRef.current?.focus() searchBarRef.current?.focus()
} }
}, [isActive]) }, [isActive, searchParams])
const onSearch = (params: TSearchParams | null) => { const onSearch = (params: TSearchParams | null) => {
setSearchParams(params) setSearchParams(params)