forked from WoWAnalyzer/WoWAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dragonflight' into chore/knip-cleanup
- Loading branch information
Showing
9 changed files
with
48 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
import Config from 'parser/Config'; | ||
import { createContext, useContext, ReactNode } from 'react'; | ||
import type Config from 'parser/Config'; | ||
import { usePlayer } from 'interface/report/context/PlayerContext'; | ||
import { useReport } from 'interface/report/context/ReportContext'; | ||
import getConfig from 'parser/getConfig'; | ||
import { wclGameVersionToExpansion } from 'game/VERSIONS'; | ||
|
||
const ConfigContext = createContext<Config | undefined>(undefined); | ||
export const useMaybeConfig = (): Config | undefined => { | ||
// this mess of try/catch papers over some historical choices to throw for these contexts instead of allowing them to return undefined. | ||
// that refactor is...big enough that i'm not doing it today | ||
let report = undefined; | ||
try { | ||
const data = useReport(); | ||
report = data.report; | ||
} catch { | ||
/* do nothing */ | ||
} | ||
let player = undefined; | ||
let combatant = undefined; | ||
|
||
export default ConfigContext; | ||
try { | ||
const playerData = usePlayer(); | ||
player = playerData.player; | ||
combatant = playerData.combatant; | ||
} catch { | ||
/* do nothing */ | ||
} | ||
|
||
export const useConfig = () => { | ||
const ctx = useContext(ConfigContext); | ||
if (ctx === undefined) { | ||
throw new Error('Unable to get Config for selected report/player combination'); | ||
if (!report || !player || !combatant) { | ||
return undefined; | ||
} | ||
return ctx; | ||
return getConfig( | ||
wclGameVersionToExpansion(report.gameVersion), | ||
combatant.specID, | ||
player, | ||
combatant, | ||
); | ||
}; | ||
|
||
interface ConfigProviderProps { | ||
children: ReactNode; | ||
config: Config | undefined; | ||
} | ||
export const ConfigProvider = ({ children, config }: ConfigProviderProps) => ( | ||
<ConfigContext.Provider value={config}>{children}</ConfigContext.Provider> | ||
); | ||
export const useConfig = (): Config => { | ||
const config = useMaybeConfig(); | ||
if (!config) { | ||
throw new Error('Unable to get Config for selected report/player combination'); | ||
} | ||
|
||
interface ReportPlayerConfigProviderProps { | ||
children: ReactNode; | ||
} | ||
export const ReportPlayerConfigProvider = ({ children }: ReportPlayerConfigProviderProps) => { | ||
const { combatant, player } = usePlayer(); | ||
const { report } = useReport(); | ||
return ( | ||
<ConfigProvider | ||
config={getConfig( | ||
wclGameVersionToExpansion(report.gameVersion), | ||
combatant.specID, | ||
player, | ||
combatant, | ||
)} | ||
> | ||
{children} | ||
</ConfigProvider> | ||
); | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters