mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix markers ui bug (#5671)
* Move loadMarkers to separate callback * Remove async from findColors --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -693,18 +693,10 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
|
|||||||
_initialTimestamp,
|
_initialTimestamp,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
const loadMarkers = useCallback(() => {
|
||||||
const player = getPlayer();
|
const player = getPlayer();
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
|
|
||||||
if (scene.paths.screenshot) {
|
|
||||||
player.poster(scene.paths.screenshot);
|
|
||||||
} else {
|
|
||||||
player.poster("");
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadMarkers() {
|
|
||||||
const loadMarkersAsync = async () => {
|
|
||||||
const markerData = scene.scene_markers.map((marker) => ({
|
const markerData = scene.scene_markers.map((marker) => ({
|
||||||
title: getMarkerTitle(marker),
|
title: getMarkerTitle(marker),
|
||||||
seconds: marker.seconds,
|
seconds: marker.seconds,
|
||||||
@@ -720,7 +712,7 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
|
|||||||
.filter((value, index, self) => self.indexOf(value) === index);
|
.filter((value, index, self) => self.indexOf(value) === index);
|
||||||
|
|
||||||
// Wait for colors
|
// Wait for colors
|
||||||
await markers.findColors(uniqueTagNames);
|
markers.findColors(uniqueTagNames);
|
||||||
|
|
||||||
const showRangeTags =
|
const showRangeTags =
|
||||||
!ScreenUtils.isMobile() && (uiConfig?.showRangeMarkers ?? true);
|
!ScreenUtils.isMobile() && (uiConfig?.showRangeMarkers ?? true);
|
||||||
@@ -753,24 +745,34 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
|
|||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
markers.addRangeMarkers(rangeMarkers);
|
markers.addRangeMarkers(rangeMarkers);
|
||||||
});
|
});
|
||||||
|
}, [getPlayer, scene, uiConfig]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const player = getPlayer();
|
||||||
|
if (!player) return;
|
||||||
|
|
||||||
|
if (scene.paths.screenshot) {
|
||||||
|
player.poster(scene.paths.screenshot);
|
||||||
|
} else {
|
||||||
|
player.poster("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the event handler outside the useEffect
|
||||||
|
const handleLoadMetadata = () => {
|
||||||
|
loadMarkers();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call our async function
|
|
||||||
void loadMarkersAsync();
|
|
||||||
}
|
|
||||||
// Ensure markers are added after player is fully ready and sources are loaded
|
// Ensure markers are added after player is fully ready and sources are loaded
|
||||||
if (player.readyState() >= 1) {
|
if (player.readyState() >= 1) {
|
||||||
loadMarkers();
|
loadMarkers();
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
player.on("loadedmetadata", () => {
|
player.on("loadedmetadata", handleLoadMetadata);
|
||||||
loadMarkers();
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
player.off("loadedmetadata", loadMarkers);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}, [getPlayer, scene, uiConfig]);
|
|
||||||
|
return () => {
|
||||||
|
player.off("loadedmetadata", handleLoadMetadata);
|
||||||
|
};
|
||||||
|
}, [getPlayer, scene, loadMarkers]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const player = getPlayer();
|
const player = getPlayer();
|
||||||
|
|||||||
@@ -259,11 +259,11 @@ class MarkersPlugin extends videojs.getPlugin("plugin") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implementing the findColors method
|
// Implementing the findColors method
|
||||||
async findColors(tagNames: string[]) {
|
findColors(tagNames: string[]) {
|
||||||
// Compute base hues for each tag
|
// Compute base hues for each tag
|
||||||
const baseHues: { [tag: string]: number } = {};
|
const baseHues: { [tag: string]: number } = {};
|
||||||
for (const tag of tagNames) {
|
for (const tag of tagNames) {
|
||||||
baseHues[tag] = await this.computeBaseHue(tag);
|
baseHues[tag] = this.computeBaseHue(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust hues to avoid similar colors
|
// Adjust hues to avoid similar colors
|
||||||
@@ -278,7 +278,7 @@ class MarkersPlugin extends videojs.getPlugin("plugin") {
|
|||||||
// Helper methods translated from Python
|
// Helper methods translated from Python
|
||||||
|
|
||||||
// Compute base hue from tag name
|
// Compute base hue from tag name
|
||||||
private async computeBaseHue(tag: string): Promise<number> {
|
private computeBaseHue(tag: string): number {
|
||||||
const hash = CryptoJS.SHA256(tag);
|
const hash = CryptoJS.SHA256(tag);
|
||||||
const hashHex = hash.toString(CryptoJS.enc.Hex);
|
const hashHex = hash.toString(CryptoJS.enc.Hex);
|
||||||
const hashInt = BigInt(`0x${hashHex}`);
|
const hashInt = BigInt(`0x${hashHex}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user