Skip to content

Commit 9dfa1ad

Browse files
committed
feat(synced-lyrics): trigger fast scroll on provider switch and improve transform calc
1 parent 150e62c commit 9dfa1ad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../../providers';
2323
import { currentLyrics, lyricsStore, setLyricsStore } from '../store';
2424
import { _ytAPI } from '../index';
25-
import { config } from '../renderer';
25+
import { config, requestFastScroll } from '../renderer';
2626

2727
import type { YtIcons } from '@/types/icons';
2828
import type { PlayerAPIEvents } from '@/types/player-api-events';
@@ -141,6 +141,7 @@ export const LyricsPicker = (props: {
141141
if (!hasManuallySwitchedProvider()) {
142142
const starred = starredProvider();
143143
if (starred !== null) {
144+
requestFastScroll(2500);
144145
setLyricsStore('provider', starred);
145146
return;
146147
}
@@ -155,13 +156,15 @@ export const LyricsPicker = (props: {
155156
force ||
156157
providerBias(lyricsStore.provider) < providerBias(provider)
157158
) {
159+
requestFastScroll(2500);
158160
setLyricsStore('provider', provider);
159161
}
160162
}
161163
});
162164

163165
const next = () => {
164166
setHasManuallySwitchedProvider(true);
167+
requestFastScroll(2500);
165168
setLyricsStore('provider', (prevProvider) => {
166169
const idx = providerNames.indexOf(prevProvider);
167170
return providerNames[(idx + 1) % providerNames.length];
@@ -170,6 +173,7 @@ export const LyricsPicker = (props: {
170173

171174
const previous = () => {
172175
setHasManuallySwitchedProvider(true);
176+
requestFastScroll(2500);
173177
setLyricsStore('provider', (prevProvider) => {
174178
const idx = providerNames.indexOf(prevProvider);
175179
return providerNames[
@@ -231,7 +235,7 @@ export const LyricsPicker = (props: {
231235
<div
232236
class="lyrics-picker-item"
233237
style={{
234-
transform: `translateX(${providerIdx() * -100 - 5}%)`,
238+
transform: `translateX(calc(${providerIdx()} * -100% - 5%))`,
235239
}}
236240
tabindex="-1"
237241
>
@@ -311,7 +315,11 @@ export const LyricsPicker = (props: {
311315
{(_, idx) => (
312316
<li
313317
class="lyrics-picker-dot"
314-
onClick={() => setLyricsStore('provider', providerNames[idx()])}
318+
onClick={() => {
319+
setHasManuallySwitchedProvider(true);
320+
requestFastScroll(2500);
321+
setLyricsStore('provider', providerNames[idx()]);
322+
}}
315323
style={{
316324
background: idx() === providerIdx() ? 'white' : 'black',
317325
}}

0 commit comments

Comments
 (0)