mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
perf: using local english cache in order to improve performance
Some checks failed
Lint / lint (push) Has been cancelled
Some checks failed
Lint / lint (push) Has been cancelled
This commit is contained in:
commit
301d9a5732
6 changed files with 190 additions and 108 deletions
|
@ -98,7 +98,11 @@
|
||||||
"got_it": "Got it",
|
"got_it": "Got it",
|
||||||
"no_shop_details": "Could not retrieve shop details.",
|
"no_shop_details": "Could not retrieve shop details.",
|
||||||
"download_options": "Download options",
|
"download_options": "Download options",
|
||||||
"download_path": "Download path"
|
"download_path": "Download path",
|
||||||
|
"previous_screenshot": "Previous screenshot",
|
||||||
|
"next_screenshot": "Next screenshot",
|
||||||
|
"screenshot": "Screenshot {{number}}",
|
||||||
|
"open_screenshot": "Open screenshot {{number}}"
|
||||||
},
|
},
|
||||||
"activation": {
|
"activation": {
|
||||||
"title": "Activate Hydra",
|
"title": "Activate Hydra",
|
||||||
|
|
|
@ -94,7 +94,11 @@
|
||||||
"got_it": "Entendi",
|
"got_it": "Entendi",
|
||||||
"no_shop_details": "Não foi possível obter os detalhes da loja.",
|
"no_shop_details": "Não foi possível obter os detalhes da loja.",
|
||||||
"download_options": "Opções de download",
|
"download_options": "Opções de download",
|
||||||
"download_path": "Diretório de download"
|
"download_path": "Diretório de download",
|
||||||
|
"previous_screenshot": "Captura de tela anterior",
|
||||||
|
"next_screenshot": "Próxima captura de tela",
|
||||||
|
"screenshot": "Captura de tela {{number}}",
|
||||||
|
"open_screenshot": "Ver captura de tela {{number}}"
|
||||||
},
|
},
|
||||||
"activation": {
|
"activation": {
|
||||||
"title": "Ativação",
|
"title": "Ativação",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { gameShopCacheRepository } from "@main/repository";
|
import { gameShopCacheRepository, steamGameRepository } from "@main/repository";
|
||||||
import { getSteamAppDetails } from "@main/services";
|
import { getSteamAppDetails } from "@main/services";
|
||||||
|
|
||||||
import type { ShopDetails, GameShop, SteamAppDetails } from "@types";
|
import type { ShopDetails, GameShop, SteamAppDetails } from "@types";
|
||||||
|
@ -9,18 +9,18 @@ const getLocalizedSteamAppDetails = (
|
||||||
objectID: string,
|
objectID: string,
|
||||||
language: string
|
language: string
|
||||||
): Promise<ShopDetails | null> => {
|
): Promise<ShopDetails | null> => {
|
||||||
const englishAppDetails = getSteamAppDetails(objectID, "english");
|
if (language === "english") {
|
||||||
|
return getSteamAppDetails(objectID, language);
|
||||||
if (language === "english") return englishAppDetails;
|
}
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
englishAppDetails,
|
steamGameRepository.findOne({ where: { id: Number(objectID) } }),
|
||||||
getSteamAppDetails(objectID, language),
|
getSteamAppDetails(objectID, language),
|
||||||
]).then(([appDetails, localizedAppDetails]) => {
|
]).then(([steamGame, localizedAppDetails]) => {
|
||||||
if (appDetails && localizedAppDetails) {
|
if (steamGame && localizedAppDetails) {
|
||||||
return {
|
return {
|
||||||
...localizedAppDetails,
|
...localizedAppDetails,
|
||||||
name: appDetails.name,
|
name: steamGame.name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ i18n
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
i18n.changeLanguage("pt-BR");
|
||||||
window.electron.updateUserPreferences({ language: i18n.language });
|
window.electron.updateUserPreferences({ language: i18n.language });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { recipe } from "@vanilla-extract/recipes";
|
||||||
import { SPACING_UNIT, vars } from "../../theme.css";
|
import { SPACING_UNIT, vars } from "../../theme.css";
|
||||||
import { style } from "@vanilla-extract/css";
|
import { style } from "@vanilla-extract/css";
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ export const gallerySliderMedia = style({
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
display: "block",
|
display: "block",
|
||||||
flexShrink: 0,
|
flexShrink: "0",
|
||||||
flexGrow: "0",
|
flexGrow: "0",
|
||||||
transition: "translate 0.3s ease-in-out",
|
transition: "translate 0.3s ease-in-out",
|
||||||
borderRadius: "4px",
|
borderRadius: "4px",
|
||||||
|
@ -54,42 +55,77 @@ export const gallerySliderPreview = style({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const gallerySliderMediaPreview = style({
|
export const mediaPreviewButton = recipe({
|
||||||
cursor: "pointer",
|
base: {
|
||||||
width: "20%",
|
cursor: "pointer",
|
||||||
height: "20%",
|
width: "20%",
|
||||||
display: "block",
|
height: "20%",
|
||||||
flexShrink: 0,
|
display: "block",
|
||||||
flexGrow: 0,
|
flexShrink: "0",
|
||||||
opacity: 0.3,
|
flexGrow: "0",
|
||||||
transition: "translate 0.3s ease-in-out, opacity 0.2s ease",
|
opacity: "0.3",
|
||||||
borderRadius: "4px",
|
transition: "translate 0.3s ease-in-out, opacity 0.2s ease",
|
||||||
border: `solid 1px ${vars.color.border}`,
|
borderRadius: "4px",
|
||||||
":hover": {
|
border: `solid 1px ${vars.color.border}`,
|
||||||
opacity: "1",
|
":hover": {
|
||||||
|
opacity: "0.8",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
active: {
|
||||||
|
true: {
|
||||||
|
opacity: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const gallerySliderMediaPreviewActive = style({
|
export const mediaPreview = style({
|
||||||
opacity: 1,
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flex: "1",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const gallerySliderButton = style({
|
export const gallerySliderButton = recipe({
|
||||||
all: "unset",
|
base: {
|
||||||
display: "block",
|
position: "absolute",
|
||||||
position: "absolute",
|
alignSelf: "center",
|
||||||
top: 0,
|
cursor: "pointer",
|
||||||
bottom: 0,
|
backgroundColor: "rgba(0, 0, 0, 0.4)",
|
||||||
padding: "1rem",
|
transition: "all 0.2s ease-in-out",
|
||||||
cursor: "pointer",
|
borderRadius: "50%",
|
||||||
transition: "background-color 100ms ease-in-out",
|
color: vars.color.muted,
|
||||||
":hover": {
|
width: "48px",
|
||||||
backgroundColor: "rgb(0, 0, 0, 0.2)",
|
height: "48px",
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
||||||
|
},
|
||||||
|
":active": {
|
||||||
|
transform: "scale(0.95)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
direction: {
|
||||||
|
left: {
|
||||||
|
left: "0",
|
||||||
|
marginLeft: `${SPACING_UNIT}px`,
|
||||||
|
transform: `translateX(${-(48 + SPACING_UNIT)}px)`,
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
right: "0",
|
||||||
|
marginRight: `${SPACING_UNIT}px`,
|
||||||
|
transform: `translateX(${48 + SPACING_UNIT}px)`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
visible: {
|
||||||
|
true: {
|
||||||
|
transform: "translateX(0)",
|
||||||
|
opacity: "1",
|
||||||
|
},
|
||||||
|
false: {
|
||||||
|
opacity: "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const gallerySliderIcons = style({
|
|
||||||
fill: vars.color.muted,
|
|
||||||
width: "2rem",
|
|
||||||
height: "2rem",
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ShopDetails, SteamMovies, SteamScreenshot } from "@types";
|
|
||||||
import { ChevronRightIcon, ChevronLeftIcon } from "@primer/octicons-react";
|
import { ChevronRightIcon, ChevronLeftIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
|
import type { ShopDetails } from "@types";
|
||||||
|
|
||||||
import * as styles from "./gallery-slider.css";
|
import * as styles from "./gallery-slider.css";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface GallerySliderProps {
|
export interface GallerySliderProps {
|
||||||
gameDetails: ShopDetails;
|
gameDetails: ShopDetails;
|
||||||
|
@ -9,6 +12,12 @@ export interface GallerySliderProps {
|
||||||
|
|
||||||
export function GallerySlider({ gameDetails }: GallerySliderProps) {
|
export function GallerySlider({ gameDetails }: GallerySliderProps) {
|
||||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const mediaContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
|
const hasScreenshots = gameDetails && gameDetails.screenshots.length;
|
||||||
|
const hasMovies = gameDetails && gameDetails.movies?.length;
|
||||||
|
|
||||||
const [mediaCount] = useState<number>(() => {
|
const [mediaCount] = useState<number>(() => {
|
||||||
if (gameDetails.screenshots && gameDetails.movies) {
|
if (gameDetails.screenshots && gameDetails.movies) {
|
||||||
|
@ -23,7 +32,7 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const [mediaIndex, setMediaIndex] = useState<number>(0);
|
const [mediaIndex, setMediaIndex] = useState<number>(0);
|
||||||
const [arrowShow, setArrowShow] = useState(false);
|
const [showArrows, setShowArrows] = useState(false);
|
||||||
|
|
||||||
const showNextImage = () => {
|
const showNextImage = () => {
|
||||||
setMediaIndex((index: number) => {
|
setMediaIndex((index: number) => {
|
||||||
|
@ -45,6 +54,20 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
|
||||||
setMediaIndex(0);
|
setMediaIndex(0);
|
||||||
}, [gameDetails]);
|
}, [gameDetails]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasMovies && mediaContainerRef.current) {
|
||||||
|
mediaContainerRef.current.childNodes.forEach((node, index) => {
|
||||||
|
if (node instanceof HTMLVideoElement) {
|
||||||
|
if (index == mediaIndex) {
|
||||||
|
node.play();
|
||||||
|
} else {
|
||||||
|
node.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [hasMovies, mediaContainerRef, mediaIndex]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (scrollContainerRef.current) {
|
if (scrollContainerRef.current) {
|
||||||
const container = scrollContainerRef.current;
|
const container = scrollContainerRef.current;
|
||||||
|
@ -55,93 +78,107 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
|
||||||
}
|
}
|
||||||
}, [gameDetails, mediaIndex, mediaCount]);
|
}, [gameDetails, mediaIndex, mediaCount]);
|
||||||
|
|
||||||
const hasScreenshots = gameDetails.screenshots.length;
|
const previews = useMemo(() => {
|
||||||
const hasMovies = gameDetails.movies?.length;
|
const screenshotPreviews =
|
||||||
|
gameDetails?.screenshots.map(({ id, path_thumbnail }) => ({
|
||||||
|
id,
|
||||||
|
thumbnail: path_thumbnail,
|
||||||
|
})) ?? [];
|
||||||
|
|
||||||
|
if (gameDetails?.movies) {
|
||||||
|
const moviePreviews = gameDetails.movies.map(({ id, thumbnail }) => ({
|
||||||
|
id,
|
||||||
|
thumbnail,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [...moviePreviews, ...screenshotPreviews];
|
||||||
|
}
|
||||||
|
|
||||||
|
return screenshotPreviews;
|
||||||
|
}, [gameDetails]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{hasScreenshots && (
|
{hasScreenshots && (
|
||||||
<div className={styles.gallerySliderContainer}>
|
<div className={styles.gallerySliderContainer}>
|
||||||
<div
|
<div
|
||||||
onMouseEnter={() => setArrowShow(true)}
|
onMouseEnter={() => setShowArrows(true)}
|
||||||
onMouseLeave={() => setArrowShow(false)}
|
onMouseLeave={() => setShowArrows(false)}
|
||||||
className={styles.gallerySliderAnimationContainer}
|
className={styles.gallerySliderAnimationContainer}
|
||||||
|
ref={mediaContainerRef}
|
||||||
>
|
>
|
||||||
{gameDetails.movies &&
|
{gameDetails.movies &&
|
||||||
gameDetails.movies.map((video: SteamMovies) => (
|
gameDetails.movies.map((video) => (
|
||||||
<video
|
<video
|
||||||
key={video.id}
|
key={video.id}
|
||||||
controls
|
controls
|
||||||
className={styles.gallerySliderMedia}
|
className={styles.gallerySliderMedia}
|
||||||
poster={video.thumbnail}
|
poster={video.thumbnail}
|
||||||
style={{ translate: `${-100 * mediaIndex}%` }}
|
style={{ translate: `${-100 * mediaIndex}%` }}
|
||||||
autoPlay
|
|
||||||
loop
|
loop
|
||||||
muted
|
muted
|
||||||
|
tabIndex={-1}
|
||||||
>
|
>
|
||||||
<source src={video.webm.max.replace("http", "https")} />
|
<source src={video.mp4.max.replace("http", "https")} />
|
||||||
</video>
|
</video>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{hasScreenshots &&
|
{hasScreenshots &&
|
||||||
gameDetails.screenshots.map(
|
gameDetails.screenshots.map((image, i) => (
|
||||||
(image: SteamScreenshot, i: number) => (
|
|
||||||
<img
|
|
||||||
key={"image-" + i}
|
|
||||||
className={styles.gallerySliderMedia}
|
|
||||||
src={image.path_full}
|
|
||||||
style={{ translate: `${-100 * mediaIndex}%` }}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
{arrowShow && (
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
onClick={showPrevImage}
|
|
||||||
type="button"
|
|
||||||
className={styles.gallerySliderButton}
|
|
||||||
style={{ left: 0 }}
|
|
||||||
>
|
|
||||||
<ChevronLeftIcon className={styles.gallerySliderIcons} />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
onClick={showNextImage}
|
|
||||||
type="button"
|
|
||||||
className={styles.gallerySliderButton}
|
|
||||||
style={{ right: 0 }}
|
|
||||||
>
|
|
||||||
<ChevronRightIcon className={styles.gallerySliderIcons} />
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={styles.gallerySliderPreview} ref={scrollContainerRef}>
|
|
||||||
{hasMovies &&
|
|
||||||
gameDetails.movies?.map((video: SteamMovies, i: number) => (
|
|
||||||
<img
|
<img
|
||||||
key={video.id}
|
key={image.id}
|
||||||
onClick={() => setMediaIndex(i)}
|
className={styles.gallerySliderMedia}
|
||||||
src={video.thumbnail}
|
src={image.path_full}
|
||||||
className={`${styles.gallerySliderMediaPreview} ${mediaIndex === i ? styles.gallerySliderMediaPreviewActive : ""}`}
|
style={{ translate: `${-100 * mediaIndex}%` }}
|
||||||
|
alt={t("screenshot", { number: i + 1 })}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{hasScreenshots &&
|
<button
|
||||||
gameDetails.screenshots.map(
|
onClick={showPrevImage}
|
||||||
(image: SteamScreenshot, i: number) => (
|
type="button"
|
||||||
<img
|
className={styles.gallerySliderButton({
|
||||||
key={"image-thumb-" + i}
|
visible: showArrows,
|
||||||
onClick={() =>
|
direction: "left",
|
||||||
setMediaIndex(
|
})}
|
||||||
i + (gameDetails.movies ? gameDetails.movies.length : 0)
|
aria-label={t("previous_screenshot")}
|
||||||
)
|
tabIndex={0}
|
||||||
}
|
>
|
||||||
className={`${styles.gallerySliderMediaPreview} ${mediaIndex === i + (gameDetails.movies ? gameDetails.movies.length : 0) ? styles.gallerySliderMediaPreviewActive : ""}`}
|
<ChevronLeftIcon size={36} />
|
||||||
src={image.path_full}
|
</button>
|
||||||
/>
|
|
||||||
)
|
<button
|
||||||
)}
|
onClick={showNextImage}
|
||||||
|
type="button"
|
||||||
|
className={styles.gallerySliderButton({
|
||||||
|
visible: showArrows,
|
||||||
|
direction: "right",
|
||||||
|
})}
|
||||||
|
aria-label={t("next_screenshot")}
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
<ChevronRightIcon size={36} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.gallerySliderPreview} ref={scrollContainerRef}>
|
||||||
|
{previews.map((media, i) => (
|
||||||
|
<button
|
||||||
|
key={media.id}
|
||||||
|
type="button"
|
||||||
|
className={styles.mediaPreviewButton({
|
||||||
|
active: mediaIndex === i,
|
||||||
|
})}
|
||||||
|
onClick={() => setMediaIndex(i)}
|
||||||
|
aria-label={t("open_screenshot", { number: i + 1 })}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={media.thumbnail}
|
||||||
|
className={styles.mediaPreview}
|
||||||
|
alt={t("screenshot", { number: i + 1 })}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue