From 78599a202ef0fee306fc37907e40c8ac95143b4c Mon Sep 17 00:00:00 2001 From: lovegaoshi <106490582+lovegaoshi@users.noreply.github.com> Date: Mon, 18 Mar 2024 06:14:43 -0700 Subject: [PATCH] feat: bvid search --- src/components/playlist/SongList/SongMenu.tsx | 17 +++++++++++++++++ src/hooks/useBiliSearch.ts | 2 +- src/localization/en/translation.json | 1 + src/localization/zhcn/translation.json | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/playlist/SongList/SongMenu.tsx b/src/components/playlist/SongList/SongMenu.tsx index 6baf1b28..dce7f29c 100644 --- a/src/components/playlist/SongList/SongMenu.tsx +++ b/src/components/playlist/SongList/SongMenu.tsx @@ -8,11 +8,14 @@ import { CopiedPlaylistMenuItem } from '@components/buttons/CopiedPlaylistButton import RenameSongButton from '@components/player/TrackInfo/RenameSong/RenameSongButton'; import useSongOperations from '@hooks/useSongOperations'; import { SearchRegex } from '@enums/Playlist'; +import { SOURCE } from '@enums/MediaFetch'; +import useBiliSearch from '@hooks/useBiliSearch'; enum ICONS { SEND_TO = 'playlist-plus', COPY_SONG_NAME = '', SEARCH_IN_PLAYLIST = 'text-search', + SEARCH_BVID = 'search-web', RELOAD = 'refresh', REMOVE = 'delete', REMOVE_AND_BAN_BVID = 'delete-forever', @@ -46,6 +49,7 @@ export default ({ usePlaylist, prepareForLayoutAnimationRender }: Props) => { state => state.setPlaylistSearchAutoFocus ); const { startRadio, radioAvailable } = useSongOperations(); + const { setSearchVal, handleSearch } = useBiliSearch({}); const closeMenu = React.useCallback(() => setSongMenuVisible(false), []); @@ -126,6 +130,19 @@ export default ({ usePlaylist, prepareForLayoutAnimationRender }: Props) => { disabled={checking} title={t('SongOperations.songSearchInPlaylistTitle')} /> + {selectedSongs()[0]?.source === SOURCE.bilivideo && ( + { + const song = selectedSongs()[0]; + setSearchVal(song.bvid); + handleSearch(song.bvid); + closeMenu(); + }} + disabled={checking} + title={t('SongOperations.BVIDSearchTitle')} + /> + )} removeSongs()} diff --git a/src/hooks/useBiliSearch.ts b/src/hooks/useBiliSearch.ts index 17d86d93..dbd843a9 100644 --- a/src/hooks/useBiliSearch.ts +++ b/src/hooks/useBiliSearch.ts @@ -7,7 +7,7 @@ import { useNoxSetting } from '../stores/useApp'; import { getDefaultSearch } from '@utils/ChromeStorage'; interface props { - onSearched: (val: any) => void; + onSearched?: (val: any) => void; searchListTitle?: string; } export default ({ diff --git a/src/localization/en/translation.json b/src/localization/en/translation.json index c02aa1b1..94a33c42 100644 --- a/src/localization/en/translation.json +++ b/src/localization/en/translation.json @@ -85,6 +85,7 @@ "songSendToTitle": "Send to...", "songRenameTitle": "Rename...", "songSearchInPlaylistTitle": "Search in Playlist", + "BVIDSearchTitle": "Search in Bilibili", "songStartRadio": "Start Radio", "songR128gain": "R128Gain", "abrepeat": "ABrepeat", diff --git a/src/localization/zhcn/translation.json b/src/localization/zhcn/translation.json index d1e58128..8c79b180 100644 --- a/src/localization/zhcn/translation.json +++ b/src/localization/zhcn/translation.json @@ -85,6 +85,7 @@ "songSendToTitle": "送往...", "songRenameTitle": "改名...", "songSearchInPlaylistTitle": "在歌单内搜索", + "BVIDSearchTitle": "bv号搜索", "songStartRadio": "播放电台", "songR128gain": "回放增益", "abrepeat": "AB重复",