Skip to content

Commit

Permalink
Merge pull request #66 from WHIZENx/update-patch
Browse files Browse the repository at this point in the history
improve performance
  • Loading branch information
WHIZENx authored Aug 26, 2024
2 parents bef2ebe + dff7d01 commit c18b446
Show file tree
Hide file tree
Showing 46 changed files with 221 additions and 178 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import StatsRanking from './pages/Sheets/StatsRanking/StatsRanking';
import { loadTheme } from './store/effects/theme.effects';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import { getDesignThemes } from './assets/themes/themes';
import { getDesignThemes } from './util/models/overrides/themes.model';
import { TRANSITION_TIME } from './util/Constants';
import { PaletteMode } from '@mui/material';
import { TypeTheme } from './enums/type.enum';
Expand Down
12 changes: 6 additions & 6 deletions src/components/Card/CardMove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ const CardMove = (props: ICardMoveComponent) => {
height={64}
alt="type-logo"
style={{ marginRight: 10 }}
src={APIService.getTypeSprite(capitalize(data?.type ?? ''))}
src={APIService.getTypeSprite(capitalize(data.type ?? ''))}
/>
<span style={{ marginRight: 5 }}>
<b>{splitAndCapitalize(data?.name, '_', ' ')}</b>
<b>{splitAndCapitalize(data.name, '_', ' ')}</b>
</span>
<span className="d-flex">
{data?.elite && <span className="type-icon-small ic elite-ic">Elite</span>}
{data?.shadow && <span className="type-icon-small ic shadow-ic">{capitalize(FORM_SHADOW)}</span>}
{data?.purified && <span className="type-icon-small ic purified-ic">{capitalize(FORM_PURIFIED)}</span>}
{data?.special && <span className="type-icon-small ic special-ic">Special</span>}
{data.elite && <span className="type-icon-small ic elite-ic">Elite</span>}
{data.shadow && <span className="type-icon-small ic shadow-ic">{capitalize(FORM_SHADOW)}</span>}
{data.purified && <span className="type-icon-small ic purified-ic">{capitalize(FORM_PURIFIED)}</span>}
{data.special && <span className="type-icon-small ic special-ic">Special</span>}
</span>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Find/FormSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import TypeInfo from '../Sprites/Type/Type';
import { FormControlLabel, Radio } from '@mui/material';
import { useDispatch } from 'react-redux';
import { Action } from 'history';
import { ToolSearching } from '../../core/models/searching.model';
import { IPokemonName } from '../../core/models/pokemon.model';
import {
Expand All @@ -37,6 +36,7 @@ import { IFormSelectComponent } from '../models/component.model';
import { TypeRaid } from '../../enums/type.enum';
import { SearchingActions } from '../../store/actions';
import { SearchingModel } from '../../store/models/searching.model';
import { Action } from 'history';

interface OptionsPokemon {
prev: IPokemonName | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/Assets/PokemonModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IAsset } from '../../../core/models/asset.model';
import { IPokemonModelComponent, PokemonModelComponent } from './models/pokemon-model.model';
import { PokemonGender } from '../../../core/models/pokemon.model';
import { IAssetPokemonModelComponent } from '../../models/component.model';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

const PokemonModel = (props: IAssetPokemonModelComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/Evolution/Evolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { IForm } from '../../../core/models/API/form.model';
import { IEvolutionComponent } from '../../models/component.model';
import { TypeSex } from '../../../enums/type.enum';
import { Action } from 'history';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

interface IPokemonEvo {
prev?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/FormChange/FormChange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Candy from '../../Sprites/Candy/Candy';
import { StoreState } from '../../../store/models/state.model';
import { IPokemonModelComponent, PokemonModelComponent } from '../Assets/models/pokemon-model.model';
import { IFromChangeComponent } from '../../models/component.model';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

const FromChange = (props: IFromChangeComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/Gender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import APIService from '../../services/API.service';
import { IPokemonGenderRatio } from '../../core/models/pokemon.model';
import { IGenderComponent } from '../models/component.model';
import { TypeSex } from '../../enums/type.enum';
import { ThemeModify } from '../../assets/themes/themes';
import { ThemeModify } from '../../util/models/overrides/themes.model';

const Gender = (props: IGenderComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/Stats/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SHADOW_ATK_BONUS, SHADOW_DEF_BONUS } from '../../../util/Constants';
import StatsBar from '../../Sprites/ProgressBar/StatsBar';
import { IStatsComponent } from '../../models/component.model';
import { TypeAction } from '../../../enums/type.enum';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

const Stats = (props: IStatsComponent) => {
const data = useSelector((state: StoreState) => state.store.data);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Raid/Raid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useTheme } from '@mui/material';
import { StoreState } from '../../store/models/state.model';
import { capitalize } from '../../util/Utils';
import { IRaidComponent } from '../models/component.model';
import { ThemeModify } from '../../assets/themes/themes';
import { ThemeModify } from '../../util/models/overrides/themes.model';

const Raid = (props: IRaidComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sprites/Type/Type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { capitalize, isNotEmpty } from '../../../util/Utils';
import './Type.scss';
import { ITypeComponent } from '../../models/component.model';
import { TypeTheme } from '../../../enums/type.enum';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

const TypeInfo = (props: ITypeComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sprites/Weather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { Fragment } from 'react';
import APIService from '../../services/API.service';
import { isNotEmpty, splitAndCapitalize } from '../../util/Utils';
import { IWeatherComponent } from '../models/component.model';
import { ThemeModify } from '../../assets/themes/themes';
import { ThemeModify } from '../../util/models/overrides/themes.model';

const Weather = (props: IWeatherComponent) => {
const theme = useTheme<ThemeModify>();
Expand Down
24 changes: 16 additions & 8 deletions src/components/Table/Counter/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { Checkbox, FormControlLabel, Switch, useTheme } from '@mui/material';
import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import APIService from '../../../services/API.service';
import { capitalize, checkPokemonGO, convertPokemonDataName, isNotEmpty, splitAndCapitalize } from '../../../util/Utils';
import {
capitalize,
checkPokemonGO,
convertColumnDataType,
convertPokemonDataName,
isNotEmpty,
splitAndCapitalize,
} from '../../../util/Utils';
import { findAssetForm } from '../../../util/Compute';
import { counterPokemon } from '../../../util/Calculate';

Expand All @@ -14,7 +21,8 @@ import { FORM_MEGA, FORM_PRIMAL, FORM_PURIFIED, FORM_SHADOW, SHADOW_DEF_BONUS }
import { ICounterModel } from './models/counter.model';
import { ICounterComponent } from '../../models/component.model';
import { TypeTheme } from '../../../enums/type.enum';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';
import { TableColumnModify } from '../../../util/models/overrides/data-table.model';

const customStyles: TableStyles = {
head: {
Expand Down Expand Up @@ -88,10 +96,10 @@ const Counter = (props: ICounterComponent) => {
const [releasedGO, setReleaseGO] = useState(true);
const [showMega, setShowMega] = useState(false);

const columns: any = [
const columns: TableColumnModify<ICounterModel>[] = [
{
name: 'Pokémon',
selector: (row: ICounterModel) => (
selector: (row) => (
<Link to={`/pokemon/${row.pokemonId}${row.pokemonForme ? `?form=${row.pokemonForme.toLowerCase().replaceAll('_', '-')}` : ''}`}>
<div className="d-flex justify-content-center">
<div
Expand Down Expand Up @@ -122,7 +130,7 @@ const Counter = (props: ICounterComponent) => {
},
{
name: 'Fast',
selector: (row: ICounterModel) => (
selector: (row) => (
<Link to={'../move/' + row.fMove.id} className="d-grid">
<div style={{ verticalAlign: 'text-bottom', marginRight: 5 }}>
<img width={28} height={28} alt="img-pokemon" src={APIService.getTypeSprite(capitalize(row.fMove.type))} />
Expand All @@ -143,7 +151,7 @@ const Counter = (props: ICounterComponent) => {
},
{
name: 'Charged',
selector: (row: ICounterModel) => (
selector: (row) => (
<Link to={'../move/' + row.cMove.id} className="d-grid">
<div style={{ verticalAlign: 'text-bottom', marginRight: 5 }}>
<img width={28} height={28} alt="img-pokemon" src={APIService.getTypeSprite(capitalize(row.cMove.type))} />
Expand Down Expand Up @@ -179,7 +187,7 @@ const Counter = (props: ICounterComponent) => {
},
{
name: '%',
selector: (row: ICounterModel) => parseFloat(row.ratio.toFixed(2)),
selector: (row) => parseFloat(row.ratio.toFixed(2)),
sortable: true,
width: '20%',
},
Expand Down Expand Up @@ -280,7 +288,7 @@ const Counter = (props: ICounterComponent) => {
</div>
<DataTable
className="table-counter-container"
columns={columns}
columns={convertColumnDataType<TableColumnModify<ICounterModel>[], ICounterModel>(columns)}
pagination={true}
customStyles={customStyles}
fixedHeader={true}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/Move/MoveTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { IPokemonQueryMove, PokemonQueryRankMove } from '../../../util/models/po
import { IPokemonData } from '../../../core/models/pokemon.model';
import { ITableMoveComponent } from '../../models/component.model';
import { TypeMove } from '../../../enums/type.enum';
import { ThemeModify } from '../../../assets/themes/themes';
import { ThemeModify } from '../../../util/models/overrides/themes.model';

interface PokemonMoves {
fastMoves: (ICombat | undefined)[];
Expand Down
3 changes: 2 additions & 1 deletion src/components/models/component.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IStatsDef,
IStatsProd,
IStatsSta,
IStatsPokemonGO,
} from '../../core/models/stats.model';
import { ITypeEffChart } from '../../core/models/type-eff.model';
import { ISelectMoveModel } from '../Input/models/select-move.model';
Expand Down Expand Up @@ -45,7 +46,7 @@ export interface ICardPokemonInfoComponent {
forme: string;
defaultImg: boolean;
types: string[];
pokemonStat: IStatsPokemon;
pokemonStat: IStatsPokemonGO;
stats: IStatsRank | null;
icon: string;
releasedGO: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/core/models/API/db.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
interface IDatabase {
interface IDatabase<T> {
command: string;
fields: IField[];
rowAsArray?: boolean;
rowCount: number;
rows: any[];
rows: T[];
viaNeonFetch?: boolean;
}

Expand All @@ -17,12 +17,12 @@ interface IField {
tableID: number;
}

export class Database implements IDatabase {
export class Database<T> implements IDatabase<T> {
command: string = '';
fields: IField[];
rowAsArray?: boolean;
rowCount: number = 0;
rows: any[];
rows: T[];
viaNeonFetch?: boolean;

constructor() {
Expand Down
6 changes: 6 additions & 0 deletions src/core/models/league.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ export class PokemonRewardSetLeague implements IPokemonRewardSetLeague {
this.name = '';
this.form = '';
}

static create(value: IPokemonRewardSetLeague) {
const obj = new PokemonRewardSetLeague();
Object.assign(obj, value);
return obj;
}
}

// tslint:disable-next-line:max-classes-per-file
Expand Down
4 changes: 2 additions & 2 deletions src/core/models/options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CombatOption implements ICombatOption {

constructor() {
this.stab = 0;
this.shadowBonus = new StatsBase(0, 0, 0);
this.shadowBonus = new StatsBase();
}
}

Expand All @@ -168,7 +168,7 @@ class BattleOption implements IBattleOption {
constructor() {
this.enemyAttackInterval = 0;
this.stab = 0;
this.shadowBonus = new StatsBase(0, 0, 0);
this.shadowBonus = new StatsBase();
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/core/models/pokemon-home.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FORM_NORMAL } from '../../util/Constants';
import { convertPokemonImageName, splitAndCapitalize } from '../../util/Utils';
import { IImage } from './asset.model';
import { IPokemonData } from './pokemon.model';
import { IStatsPokemon } from './stats.model';
import { IStatsPokemon, IStatsPokemonGO, StatsPokemon, StatsPokemonGO } from './stats.model';

export interface IPokemonHomeModel {
id: number;
Expand All @@ -17,7 +17,7 @@ export interface IPokemonHomeModel {
gen: number;
region: string | null;
version: number;
goStats: IStatsPokemon;
goStats: IStatsPokemonGO;
class: string | null;
releasedGO: boolean;
image: IImage;
Expand All @@ -31,11 +31,11 @@ export class PokemonHomeModel implements IPokemonHomeModel {
color: string;
sprite: string;
baseSpecies: string | null;
baseStats: IStatsPokemon;
baseStats: IStatsPokemon = new StatsPokemon();
gen: number;
region: string | null;
version: number;
goStats: IStatsPokemon;
goStats: IStatsPokemonGO = new StatsPokemonGO();
class: string | null;
releasedGO: boolean;
image: IImage;
Expand All @@ -56,11 +56,12 @@ export class PokemonHomeModel implements IPokemonHomeModel {
this.gen = item.gen;
this.region = item.region;
this.version = versionList.indexOf(splitAndCapitalize(item.version, '-', ' '));
this.goStats = {
this.goStats = StatsPokemonGO.create({
atk: item.baseStats.atk,
def: item.baseStats.def,
sta: item.baseStats.sta,
};
sta: item.baseStats.sta ?? 0,
prod: item.baseStats.atk * item.baseStats.def * (item.baseStats.sta ?? 0),
});
this.class = item.pokemonClass;
this.releasedGO = item.releasedGO;
this.image = {
Expand Down
4 changes: 2 additions & 2 deletions src/core/models/pokemon.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { capitalize, replaceTempMoveName } from '../../util/Utils';
import { ICombat } from './combat.model';
import { FORM_GALARIAN, FORM_HISUIAN, FORM_NORMAL, genList } from '../../util/Constants';
import { IStatsPokemon, IStatsPokemonGO, StatsPokemon, StatsPokemonGO } from './stats.model';
import { IStatsBase, IStatsPokemon, IStatsPokemonGO, StatsPokemon, StatsPokemonGO } from './stats.model';
import { ISelectMoveModel } from '../../components/Input/models/select-move.model';
import { IEvoList, ITempEvo } from './evolution.model';

Expand All @@ -20,7 +20,7 @@ export interface PokemonGender {
export interface IPokemonDataStats {
level: number;
isShadow: boolean;
iv: IStatsPokemon;
iv: IStatsBase;
}

interface IPokemonFormChange {
Expand Down
4 changes: 2 additions & 2 deletions src/core/models/pvp.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IPokemonTeamData } from '../../pages/PVP/models/battle.model';
import { ICombat } from './combat.model';
import { IPokemonData, PokemonData } from './pokemon.model';
import { IStatsAtk, IStatsDef, IStatsPokemon, IStatsSta } from './stats.model';
import { IStatsAtk, IStatsBase, IStatsDef, IStatsSta } from './stats.model';

export interface PVPDataModel {
rankings: PVPInfo[];
Expand All @@ -27,7 +27,7 @@ export interface Performers {
speciesId: string;
pokemonData: IPokemonData | undefined;
form: string | null;
stats: IStatsPokemon;
stats: IStatsBase;
atk: IStatsAtk | undefined;
def: IStatsDef | undefined;
sta: IStatsSta | undefined;
Expand Down
Loading

0 comments on commit c18b446

Please sign in to comment.