Skip to content

Commit 1614cf0

Browse files
committed
feat: Expose RandomGames component to exts
feat: Expose useContextMenu and useLocalization hooks to exts fix: Make sure Lang provider is covering Dynamic component provider refactor: Make openGameContextMenu a func from useContextMenu refactor: Replace instances of useContext(LangContext) with standardized useLocalization hook
1 parent eaad1ce commit 1614cf0

40 files changed

+640
-661
lines changed

docs/development/lang.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { LangContext } from '@renderer/util/lang';
1111

1212
function BoringTextBox() {
1313
// Load the context
14-
const strings = React.useContext(LangContext);
14+
const strings = useLocalization();
1515

1616
// Pretend we're loading by returning `Loading` :^)
1717
return (

src/renderer/components/ActivityRoutes.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import { TagsPage } from './pages/TagsPage';
99
import { FpfssPage } from './pages/FpfssPage';
1010

1111
export type ActivityRoutesProps = {
12-
onGameContextMenu: (event: React.MouseEvent, gameId: string, logoPath: string, screenshotPath: string) => void;
1312
manualUrl: string;
1413
}
1514

16-
export function ActivityRoutes({ onGameContextMenu, manualUrl }: ActivityRoutesProps) {
15+
export function ActivityRoutes({ manualUrl }: ActivityRoutesProps) {
1716
return (
1817
<>
1918
<ActivityRoute path={Paths.HOME} exact>
20-
<HomePage onGameContextMenu={onGameContextMenu}/>
19+
<HomePage/>
2120
</ActivityRoute>
2221
<ActivityRoute path={Paths.TAGS}>
2322
<TagsPage/>

src/renderer/components/BrowsePageDisplay.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

22
import { useAppDispatch, useAppSelector } from '@renderer/hooks/useAppSelector';
3+
import { useLocalization } from '@renderer/hooks/useLocalization';
34
import { requestRange, selectGame, setGridScroll, setListScroll } from '@renderer/store/search/slice';
45
import { gameDragDataType, getPlatformIconURL } from '@renderer/Util';
5-
import { LangContext } from '@renderer/util/lang';
66
import { BackIn } from '@shared/back/types';
77
import { calcScale } from '@shared/Util';
88
import { isGame } from '@shared/utils/misc';
99
import { formatString } from '@shared/utils/StringFormatter';
1010
import { delayedThrottle } from '@shared/utils/throttle';
1111
import { Content, Game, Playlist } from 'flashpoint-launcher';
1212
import { BrowsePageDisplayGridProps, BrowsePageDisplayListProps, BrowsePageDisplayProps } from 'flashpoint-launcher-renderer';
13-
import React, { useContext, useState } from 'react';
13+
import React, { useState } from 'react';
1414
import { ScrollIndices } from 'react-virtualized';
1515
import { GameGrid } from './GameGrid';
1616
import { GameList } from './GameList';
@@ -247,7 +247,7 @@ type BasicNoRowRendererProps = {
247247
}
248248

249249
export function BasicNoRowsRenderer(props: BasicNoRowRendererProps) {
250-
const strings = useContext(LangContext);
250+
const strings = useLocalization();
251251
const { contentTotal, selectedPlaylist } = props;
252252

253253
return (

src/renderer/components/ConfirmElement.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { withConfirmDialog, WithConfirmDialogProps } from '@renderer/containers/withConfirmDialog';
2-
import { LangContext } from '@renderer/util/lang';
2+
import { useLocalization } from '@renderer/hooks/useLocalization';
33
import { Subtract } from '@shared/interfaces';
44
import * as React from 'react';
55

@@ -28,7 +28,7 @@ type ConfirmElementComponentProps<T = undefined> = {
2828
// Wrapper component around the "useConfirm" hook.
2929
function ConfirmElementComponent<T = undefined>(props: ConfirmElementComponentProps<T>) {
3030
const { onConfirm, message, render, extra } = props;
31-
const strings = React.useContext(LangContext);
31+
const strings = useLocalization();
3232
const confirm = async () => {
3333
if (onConfirm) {
3434
const res = await props.openConfirmDialog(message, [strings.misc.yes, strings.misc.no], 1, 0);

src/renderer/components/CurateBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@renderer/components/CurateBoxInputRow';
88
import { GameImageSplit } from '@renderer/components/GameImageSplit';
99
import { useAppDispatch } from '@renderer/hooks/useAppSelector';
10+
import { useLocalization } from '@renderer/hooks/useLocalization';
1011
import {
1112
AddAppType,
1213
addPlatform,
@@ -17,7 +18,6 @@ import {
1718
setPrimaryPlatform
1819
} from '@renderer/store/curate/slice';
1920
import { axios, getCurationURL, getPlatformIconURL } from '@renderer/Util';
20-
import { LangContext } from '@renderer/util/lang';
2121
import { BackIn, CurationImageEnum } from '@shared/back/types';
2222
import { GamePropSuggestions } from '@shared/interfaces';
2323
import { mapRuffleSupportString } from '@shared/utils/misc';
@@ -49,7 +49,7 @@ export type CurateBoxProps = {
4949
}
5050

5151
export function CurateBox(props: CurateBoxProps) {
52-
const strings = React.useContext(LangContext);
52+
const strings = useLocalization();
5353
const disabled = !!props.curation.locked;
5454
const dispatch = useAppDispatch();
5555
const folder = props.curation.folder;

src/renderer/components/CurateBoxAddApp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useAppDispatch } from '@renderer/hooks/useAppSelector';
2+
import { useLocalization } from '@renderer/hooks/useLocalization';
23
import { editAddApp, removeAddApp } from '@renderer/store/curate/slice';
34
import { BackIn } from '@shared/back/types';
45
import { AddAppCuration, AddAppCurationMeta } from '@shared/curate/types';
56
import { Platform } from 'flashpoint-launcher';
67
import * as React from 'react';
78
import { Dispatch } from 'redux';
8-
import { LangContext } from '../util/lang';
99
import { CurateBoxRow } from './CurateBoxRow';
1010
import { InputField } from './InputField';
1111
import { SimpleButton } from './SimpleButton';
@@ -37,7 +37,7 @@ export function CurateBoxAddApp(props: CurateBoxAddAppProps) {
3737
const editable = true;
3838
const disabled = props.disabled;
3939
// Localized strings
40-
const strings = React.useContext(LangContext);
40+
const strings = useLocalization();
4141
const specialType = props.addApp.applicationPath === ':extras:' || props.addApp.applicationPath === ':message:';
4242
let lcString = strings.browse.launchCommand;
4343
let lcPlaceholderString = strings.browse.noLaunchCommand;

src/renderer/components/CurateBoxContentTree.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { getPointer } from '@renderer/context/MenuContext';
22
import { useAppDispatch } from '@renderer/hooks/useAppSelector';
33
import { useContextMenu } from '@renderer/hooks/useContextMenu';
4+
import { useLocalization } from '@renderer/hooks/useLocalization';
45
import { toggleContentNodeView } from '@renderer/store/curate/slice';
5-
import { LangContext } from '@renderer/util/lang';
66
import { CURATIONS_FOLDER_WORKING } from '@shared/constants';
77
import { genFlatContentTree, sizeToString } from '@shared/Util';
88
import { ContentTree, FlatContentTreeNode } from 'flashpoint-launcher';
9+
import { MenuItemType } from 'flashpoint-launcher-renderer';
910
import * as path from 'node:path';
10-
import React, { useContext } from 'react';
11+
import React from 'react';
1112
import { AutoSizer, List, ListRowProps } from 'react-virtualized';
12-
import { MenuItemType } from './Menu';
1313
import { OpenIcon } from './OpenIcon';
1414

1515
const RENDERER_OVERSCAN = 50;
@@ -23,7 +23,7 @@ export type CurateBoxContentTreeProps = {
2323
export function CurateBoxContentTree(props: CurateBoxContentTreeProps) {
2424
const { folder, launchPath, contentTree } = props;
2525
const dispatch = useAppDispatch();
26-
const strings = useContext(LangContext);
26+
const strings = useLocalization();
2727
const flatTree = genFlatContentTree(contentTree);
2828
const { openMenu } = useContextMenu();
2929

src/renderer/components/CurateBoxInputRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { CurateBoxRow } from '@renderer/components/CurateBoxRow';
22
import { InputElement, InputField, InputFieldEntry } from '@renderer/components/InputField';
33
import { useAppDispatch } from '@renderer/hooks/useAppSelector';
4+
import { useLocalization } from '@renderer/hooks/useLocalization';
45
import { editCurationMeta } from '@renderer/store/curate/slice';
5-
import { LangContext } from '@renderer/util/lang';
66
import { CurationMeta } from '@shared/curate/types';
77
import { Tag, TagCategory, TagSuggestion } from 'flashpoint-launcher';
88
import * as React from 'react';
@@ -120,7 +120,7 @@ export type CurateBoxTagDropdownInputRowProps = CurateBoxInputRowProps & {
120120
}
121121

122122
export function CurateBoxTagDropdownInputRow(props: CurateBoxTagDropdownInputRowProps) {
123-
const strings = React.useContext(LangContext);
123+
const strings = useLocalization();
124124

125125
const onSubmitTag = (text: string) => {
126126
const tags = text.split(';');

src/renderer/components/CurateBoxWarnings.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
import { useLocalization } from '@renderer/hooks/useLocalization';
12
import { CurationWarnings, LangContainer } from 'flashpoint-launcher';
2-
import * as React from 'react';
3-
import { LangContext } from '../util/lang';
43

54
export type CurateBoxWarningsProps = {
65
/** Warnings to display. */
@@ -9,7 +8,7 @@ export type CurateBoxWarningsProps = {
98

109
// The part of a Curation Box that displays all the warnings (if any).
1110
export function CurateBoxWarnings(props: CurateBoxWarningsProps) {
12-
const strings = React.useContext(LangContext).curate;
11+
const strings = useLocalization().curate;
1312
const { warnings } = props;
1413
// Count the number of warnings
1514
const warningCount = props.warnings.writtenWarnings.length;

src/renderer/components/Footer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useViewName } from '@renderer/hooks/search';
22
import { useAppDispatch, useAppSelector } from '@renderer/hooks/useAppSelector';
3+
import { useLocalization } from '@renderer/hooks/useLocalization';
34
import { setMainState } from '@renderer/store/main/slice';
45
import { updatePreferences } from '@renderer/store/preferences/slice';
56
import { GENERAL_VIEW_ID } from '@renderer/store/search/slice';
@@ -9,14 +10,12 @@ import { getLibraryItemTitle } from '@shared/library/util';
910
import { formatString } from '@shared/utils/StringFormatter';
1011
import { ScaleValues } from 'flashpoint-launcher';
1112
import * as React from 'react';
12-
import { useContext } from 'react';
1313
import { useLocation } from 'react-router-dom';
1414
import { getViewName } from '../Util';
15-
import { LangContext } from '../util/lang';
1615
import { FooterScaler } from './FooterScaler';
1716

1817
export function Footer() {
19-
const strings = useContext(LangContext);
18+
const strings = useLocalization();
2019
const dispatch = useAppDispatch();
2120
const allGamesTotal = useAppSelector(state => state.main.gamesTotal);
2221
const componentStatuses = useAppSelector(state => state.main.componentStatuses);

0 commit comments

Comments
 (0)