fix: fixing code quality issues

This commit is contained in:
Chubby Granny Chaser
2025-11-29 02:39:21 +00:00
parent f28c867479
commit 1fc87f93b7
7 changed files with 29 additions and 27 deletions

View File

@@ -1,11 +1,11 @@
import React from "react"; import React from "react";
interface HighlightTextProps { interface HighlightTextProps {
text: string; readonly text: string;
query: string; readonly query: string;
} }
export function HighlightText({ text, query }: HighlightTextProps) { export function HighlightText({ text, query }: Readonly<HighlightTextProps>) {
if (!query.trim()) { if (!query.trim()) {
return <>{text}</>; return <>{text}</>;
} }
@@ -20,7 +20,7 @@ export function HighlightText({ text, query }: HighlightTextProps) {
} }
const textWords = text.split(/\b/); const textWords = text.split(/\b/);
const matches: Array<{ start: number; end: number; text: string }> = []; const matches: { start: number; end: number; text: string }[] = [];
let currentIndex = 0; let currentIndex = 0;
textWords.forEach((word) => { textWords.forEach((word) => {
@@ -45,7 +45,7 @@ export function HighlightText({ text, query }: HighlightTextProps) {
matches.sort((a, b) => a.start - b.start); matches.sort((a, b) => a.start - b.start);
const mergedMatches: Array<{ start: number; end: number }> = []; const mergedMatches: { start: number; end: number }[] = [];
if (matches.length === 0) { if (matches.length === 0) {
return <>{text}</>; return <>{text}</>;
@@ -63,7 +63,7 @@ export function HighlightText({ text, query }: HighlightTextProps) {
} }
mergedMatches.push(current); mergedMatches.push(current);
const parts: Array<{ text: string; highlight: boolean }> = []; const parts: { text: string; highlight: boolean; key: string }[] = [];
let lastIndex = 0; let lastIndex = 0;
mergedMatches.forEach((match) => { mergedMatches.forEach((match) => {
@@ -71,12 +71,14 @@ export function HighlightText({ text, query }: HighlightTextProps) {
parts.push({ parts.push({
text: text.slice(lastIndex, match.start), text: text.slice(lastIndex, match.start),
highlight: false, highlight: false,
key: `${lastIndex}-${match.start}`,
}); });
} }
parts.push({ parts.push({
text: text.slice(match.start, match.end), text: text.slice(match.start, match.end),
highlight: true, highlight: true,
key: `${match.start}-${match.end}`,
}); });
lastIndex = match.end; lastIndex = match.end;
@@ -86,18 +88,19 @@ export function HighlightText({ text, query }: HighlightTextProps) {
parts.push({ parts.push({
text: text.slice(lastIndex), text: text.slice(lastIndex),
highlight: false, highlight: false,
key: `${lastIndex}-${text.length}`,
}); });
} }
return ( return (
<> <>
{parts.map((part, index) => {parts.map((part) =>
part.highlight ? ( part.highlight ? (
<mark key={index} className="search-dropdown__highlight"> <mark key={part.key} className="search-dropdown__highlight">
{part.text} {part.text}
</mark> </mark>
) : ( ) : (
<React.Fragment key={index}>{part.text}</React.Fragment> <React.Fragment key={part.key}>{part.text}</React.Fragment>
) )
)} )}
</> </>

View File

@@ -46,8 +46,8 @@
justify-content: center; justify-content: center;
&:hover { &:hover {
color: #dadbe1; color: #ffffff;
background-color: rgba(255, 255, 255, 0.1); background-color: rgba(255, 255, 255, 0.15);
} }
} }
@@ -83,8 +83,8 @@
background-color: transparent; background-color: transparent;
&:hover { &:hover {
color: #ff5555; color: #ff3333;
background-color: rgba(255, 85, 85, 0.1); background-color: rgba(255, 85, 85, 0.2);
} }
} }
@@ -144,8 +144,8 @@
} }
&__highlight { &__highlight {
background-color: rgba(255, 193, 7, 0.3); background-color: rgba(255, 193, 7, 0.4);
color: #ffc107; color: #ffa000;
font-weight: 600; font-weight: 600;
padding: 0 2px; padding: 0 2px;
border-radius: 2px; border-radius: 2px;

View File

@@ -3,7 +3,6 @@ import { createContext, useCallback, useEffect, useRef, useState } from "react";
import { setHeaderTitle } from "@renderer/features"; import { setHeaderTitle } from "@renderer/features";
import { levelDBService } from "@renderer/services/leveldb.service"; import { levelDBService } from "@renderer/services/leveldb.service";
import { orderBy } from "lodash-es"; import { orderBy } from "lodash-es";
import type { DownloadSource } from "@types";
import { getSteamLanguage } from "@renderer/helpers"; import { getSteamLanguage } from "@renderer/helpers";
import { import {
useAppDispatch, useAppDispatch,
@@ -13,6 +12,7 @@ import {
} from "@renderer/hooks"; } from "@renderer/hooks";
import type { import type {
DownloadSource,
GameRepack, GameRepack,
GameShop, GameShop,
GameStats, GameStats,

View File

@@ -1,6 +1,7 @@
import { useState, useEffect, useCallback, useRef } from "react"; import { useState, useEffect, useCallback, useRef } from "react";
import { useAppSelector } from "./redux"; import { useAppSelector } from "./redux";
import { debounce } from "lodash-es"; import { debounce } from "lodash-es";
import { logger } from "@renderer/logger";
export interface SearchSuggestion { export interface SearchSuggestion {
title: string; title: string;
@@ -74,13 +75,13 @@ export function useSearchSuggestions(
setIsLoading(true); setIsLoading(true);
try { try {
const response = await window.electron.hydraApi.get< const response = await globalThis.electron.hydraApi.get<
Array<{ {
title: string; title: string;
objectId: string; objectId: string;
shop: string; shop: string;
iconUrl: string | null; iconUrl: string | null;
}> }[]
>("/catalogue/search/suggestions", { >("/catalogue/search/suggestions", {
params: { params: {
query: searchQuery, query: searchQuery,
@@ -102,6 +103,7 @@ export function useSearchSuggestions(
} catch (error) { } catch (error) {
if (!abortController.signal.aborted) { if (!abortController.signal.aborted) {
setSuggestions([]); setSuggestions([]);
logger.error("Failed to fetch catalogue suggestions", error);
} }
} finally { } finally {
if (!abortController.signal.aborted) { if (!abortController.signal.aborted) {

View File

@@ -1,7 +1,7 @@
import { useContext, useRef, useState } from "react"; import { useContext, useRef, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Button, CheckboxField, Modal, TextField } from "@renderer/components"; import { Button, CheckboxField, Modal, TextField } from "@renderer/components";
import type { LibraryGame, ShortcutLocation } from "@types"; import type { Game, LibraryGame, ShortcutLocation } from "@types";
import { gameDetailsContext } from "@renderer/context"; import { gameDetailsContext } from "@renderer/context";
import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal"; import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal";
import { useDownload, useToast, useUserDetails } from "@renderer/hooks"; import { useDownload, useToast, useUserDetails } from "@renderer/hooks";
@@ -13,7 +13,6 @@ import SteamLogo from "@renderer/assets/steam-logo.svg?react";
import { debounce } from "lodash-es"; import { debounce } from "lodash-es";
import { levelDBService } from "@renderer/services/leveldb.service"; import { levelDBService } from "@renderer/services/leveldb.service";
import { getGameKey } from "@renderer/helpers"; import { getGameKey } from "@renderer/helpers";
import type { Game } from "@types";
import "./game-options-modal.scss"; import "./game-options-modal.scss";
import { logger } from "@renderer/logger"; import { logger } from "@renderer/logger";
@@ -84,9 +83,10 @@ export function GameOptionsModal({
"games" "games"
)) as Game | null; )) as Game | null;
if (gameData) { if (gameData) {
const trimmedValue = value.trim();
const updated = { const updated = {
...gameData, ...gameData,
launchOptions: value.trim() !== "" ? value : null, launchOptions: trimmedValue ? trimmedValue : null,
}; };
await levelDBService.put(gameKey, updated, "games"); await levelDBService.put(gameKey, updated, "games");
} }

View File

@@ -15,7 +15,7 @@ import {
TextField, TextField,
CheckboxField, CheckboxField,
} from "@renderer/components"; } from "@renderer/components";
import type { DownloadSource, GameRepack } from "@types"; import type { DownloadSource, Game, GameRepack } from "@types";
import { DownloadSettingsModal } from "./download-settings-modal"; import { DownloadSettingsModal } from "./download-settings-modal";
import { gameDetailsContext } from "@renderer/context"; import { gameDetailsContext } from "@renderer/context";
@@ -25,7 +25,6 @@ import { useDate, useFeature, useAppDispatch } from "@renderer/hooks";
import { clearNewDownloadOptions } from "@renderer/features"; import { clearNewDownloadOptions } from "@renderer/features";
import { levelDBService } from "@renderer/services/leveldb.service"; import { levelDBService } from "@renderer/services/leveldb.service";
import { getGameKey } from "@renderer/helpers"; import { getGameKey } from "@renderer/helpers";
import type { Game } from "@types";
import "./repacks-modal.scss"; import "./repacks-modal.scss";
export interface RepacksModalProps { export interface RepacksModalProps {
@@ -152,7 +151,6 @@ export function RepacksModal({
}; };
return levelDBService.put(gameKey, updated, "games"); return levelDBService.put(gameKey, updated, "games");
} }
return Promise.resolve();
}) })
.catch(() => {}); .catch(() => {});

View File

@@ -2,13 +2,12 @@ import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { levelDBService } from "@renderer/services/leveldb.service"; import { levelDBService } from "@renderer/services/leveldb.service";
import { orderBy } from "lodash-es"; import { orderBy } from "lodash-es";
import type { DownloadSource } from "@types";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import Skeleton, { SkeletonTheme } from "react-loading-skeleton"; import Skeleton, { SkeletonTheme } from "react-loading-skeleton";
import { Button, GameCard, Hero } from "@renderer/components"; import { Button, GameCard, Hero } from "@renderer/components";
import type { ShopAssets, Steam250Game } from "@types"; import type { DownloadSource, ShopAssets, Steam250Game } from "@types";
import flameIconStatic from "@renderer/assets/icons/flame-static.png"; import flameIconStatic from "@renderer/assets/icons/flame-static.png";
import flameIconAnimated from "@renderer/assets/icons/flame-animated.gif"; import flameIconAnimated from "@renderer/assets/icons/flame-animated.gif";