Skip to content

Commit

Permalink
Merge pull request #1607 from nukeop/feature.reset-lyrics-scroll
Browse files Browse the repository at this point in the history
Reset lyrics view scroll position for new song
  • Loading branch information
nukeop committed May 17, 2024
2 parents 43629fc + 9c8dded commit 113153a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/app/app/actions/lyrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export const lyricsSearchSuccess = createStandardAction(Lyrics.LYRICS_SEARCH_SUC
};
});

export const lyricsResetScroll = createStandardAction(Lyrics.LYRICS_RESET_SCROLL)();

export function lyricsSearch(track: Track) {
return (dispatch, getState) => {
dispatch(lyricsResetScroll());
dispatch(lyricsSearchStart(true));
const providers = getState().plugin.plugins.lyricsProviders;
const selectedProvider = getState().plugin.selected.lyricsProviders;
Expand Down
11 changes: 9 additions & 2 deletions packages/app/app/components/LyricsView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import { Icon } from 'semantic-ui-react';
import { useTranslation } from 'react-i18next';

Expand All @@ -18,8 +18,15 @@ export const LyricsView: React.FC<LyricsViewProps> = ({
track
}) => {
const { t } = useTranslation('lyrics');
const lyricsRef = useRef<HTMLDivElement>(null);

return <div className={styles.lyrics_view}>
useEffect(() => {
if (lyricsRef.current) {
lyricsRef.current.scrollTop = 0;
}
}, [lyricsSearchResult]);

return <div className={styles.lyrics_view} ref={lyricsRef}>
{
!track &&
<div className={styles.empty_state}>
Expand Down
6 changes: 5 additions & 1 deletion packages/app/app/reducers/lyrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export default function LyricsReducer (state = initialState, action: LyricsActio
switch (action.type) {
case getType(LyricsActions.lyricsSearchStart):
return Object.assign({}, state, {
playbackStreamLoading: action.payload
lyricsSearchStarted: true
});
case getType(LyricsActions.lyricsSearchSuccess):
return Object.assign({}, state, {
lyricsSearchResult: action.payload
});
case getType(LyricsActions.lyricsResetScroll):
return Object.assign({}, state, {
lyricsSearchResult: ''
});
default:
return state;
}
Expand Down

0 comments on commit 113153a

Please sign in to comment.