mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2025-12-07 08:35:36 +00:00
feat(Update to 2): Overrides leagues api call
Overrides the leagues api call since it doesn't have an endpoint rn
This commit is contained in:
@@ -1,97 +1,118 @@
|
|||||||
import { computed, shallowRef, readonly } from 'vue'
|
import { computed, shallowRef, readonly } from 'vue';
|
||||||
import { createGlobalState } from '@vueuse/core'
|
import { createGlobalState } from '@vueuse/core';
|
||||||
import { AppConfig, poeWebApi } from '@/web/Config'
|
import { AppConfig, poeWebApi } from '@/web/Config';
|
||||||
import { Host } from './IPC'
|
import { Host } from './IPC';
|
||||||
|
|
||||||
// pc-ggg, pc-garena
|
// pc-ggg, pc-garena
|
||||||
// const PERMANENT_SC = ['Standard', '標準模式']
|
// const PERMANENT_SC = ['Standard', '標準模式']
|
||||||
const PERMANENT_HC = ['Hardcore', '專家模式']
|
const PERMANENT_HC = ['Hardcore', '專家模式'];
|
||||||
|
|
||||||
interface ApiLeague {
|
interface ApiLeague {
|
||||||
id: string
|
id: string;
|
||||||
event?: boolean
|
event?: boolean;
|
||||||
rules: Array<{ id: string }>
|
rules: Array<{ id: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_POE2_LEAGUES: ApiLeague[] = [
|
||||||
|
{ id: 'Standard', rules: [] },
|
||||||
|
{
|
||||||
|
id: 'Hardcore',
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
id: 'Hardcore',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
interface League {
|
interface League {
|
||||||
id: string
|
id: string;
|
||||||
isPopular: boolean
|
isPopular: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useLeagues = createGlobalState(() => {
|
export const useLeagues = createGlobalState(() => {
|
||||||
const isLoading = shallowRef(false)
|
const isLoading = shallowRef(false);
|
||||||
const error = shallowRef<string | null>(null)
|
const error = shallowRef<string | null>(null);
|
||||||
const tradeLeagues = shallowRef<League[]>([])
|
const tradeLeagues = shallowRef<League[]>([]);
|
||||||
|
|
||||||
const selectedId = computed<string | undefined>({
|
const selectedId = computed<string | undefined>({
|
||||||
get () {
|
get() {
|
||||||
return (tradeLeagues.value.length)
|
return tradeLeagues.value.length ? AppConfig().leagueId : undefined;
|
||||||
? AppConfig().leagueId
|
},
|
||||||
: undefined
|
set(id) {
|
||||||
},
|
AppConfig().leagueId = id;
|
||||||
set (id) {
|
},
|
||||||
AppConfig().leagueId = id
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const selected = computed(() => {
|
const selected = computed(() => {
|
||||||
const { leagueId } = AppConfig()
|
const { leagueId } = AppConfig();
|
||||||
if (!tradeLeagues.value || !leagueId) return undefined
|
if (!tradeLeagues.value || !leagueId) return undefined;
|
||||||
const listed = tradeLeagues.value.find(league => league.id === leagueId)
|
const listed = tradeLeagues.value.find((league) => league.id === leagueId);
|
||||||
return {
|
return {
|
||||||
id: leagueId,
|
id: leagueId,
|
||||||
realm: AppConfig().realm,
|
realm: AppConfig().realm,
|
||||||
isPopular: !isPrivateLeague(leagueId) && Boolean(listed?.isPopular)
|
isPopular: !isPrivateLeague(leagueId) && Boolean(listed?.isPopular),
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|
||||||
async function load () {
|
async function load() {
|
||||||
isLoading.value = true
|
isLoading.value = true;
|
||||||
error.value = null
|
error.value = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await Host.proxy(`${poeWebApi()}/api/leagues?type=main&realm=pc`)
|
const response = await Host.proxy(
|
||||||
if (!response.ok) throw new Error(JSON.stringify(Object.fromEntries(response.headers)))
|
`${poeWebApi()}/api/leagues?type=main&realm=pc`
|
||||||
const leagues: ApiLeague[] = await response.json()
|
);
|
||||||
tradeLeagues.value = leagues
|
if (!response.ok)
|
||||||
.filter(league =>
|
throw new Error(JSON.stringify(Object.fromEntries(response.headers)));
|
||||||
!PERMANENT_HC.includes(league.id) &&
|
// const leagues: ApiLeague[] = await response.json();
|
||||||
!league.rules.some(rule => rule.id === 'NoParties' ||
|
const leagues: ApiLeague[] = DEFAULT_POE2_LEAGUES;
|
||||||
(rule.id === 'HardMode' && !league.event)))
|
tradeLeagues.value = leagues
|
||||||
.map(league => {
|
.filter(
|
||||||
return { id: league.id, isPopular: true }
|
(league) =>
|
||||||
})
|
!PERMANENT_HC.includes(league.id) &&
|
||||||
|
!league.rules.some(
|
||||||
|
(rule) =>
|
||||||
|
rule.id === 'NoParties' ||
|
||||||
|
(rule.id === 'HardMode' && !league.event)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((league) => {
|
||||||
|
return { id: league.id, isPopular: true };
|
||||||
|
});
|
||||||
|
|
||||||
const leagueIsAlive = tradeLeagues.value.some(league => league.id === selectedId.value)
|
const leagueIsAlive = tradeLeagues.value.some(
|
||||||
if (!leagueIsAlive && !isPrivateLeague(selectedId.value ?? '')) {
|
(league) => league.id === selectedId.value
|
||||||
if (tradeLeagues.value.length > 1) {
|
);
|
||||||
const TMP_CHALLENGE = 1
|
if (!leagueIsAlive && !isPrivateLeague(selectedId.value ?? '')) {
|
||||||
selectedId.value = tradeLeagues.value[TMP_CHALLENGE].id
|
if (tradeLeagues.value.length > 1) {
|
||||||
} else {
|
const TMP_CHALLENGE = 1;
|
||||||
const STANDARD = 0
|
selectedId.value = tradeLeagues.value[TMP_CHALLENGE].id;
|
||||||
selectedId.value = tradeLeagues.value[STANDARD].id
|
} else {
|
||||||
}
|
const STANDARD = 0;
|
||||||
}
|
selectedId.value = tradeLeagues.value[STANDARD].id;
|
||||||
} catch (e) {
|
}
|
||||||
error.value = (e as Error).message
|
}
|
||||||
} finally {
|
} catch (e) {
|
||||||
isLoading.value = false
|
error.value = (e as Error).message;
|
||||||
}
|
} finally {
|
||||||
}
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
selectedId,
|
selectedId,
|
||||||
selected,
|
selected,
|
||||||
list: readonly(tradeLeagues),
|
list: readonly(tradeLeagues),
|
||||||
load
|
load,
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|
||||||
function isPrivateLeague (id: string) {
|
function isPrivateLeague(id: string) {
|
||||||
if (id.includes('Ruthless')) {
|
if (id.includes('Ruthless')) {
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
return /\(PL\d+\)$/.test(id)
|
return /\(PL\d+\)$/.test(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user