Skip to content

Commit

Permalink
client select
Browse files Browse the repository at this point in the history
  • Loading branch information
userXinos committed May 7, 2024
1 parent 5666c9c commit 5a393c4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 65 additions & 33 deletions src/components/CompendiumPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@

<div class="header">
<div class="content">
<div>
<div
v-if="user?.alts?.length"
class="select alt-switch"
>
<select @change="(e) => selectUserAlts(e.target.value)">
<option
:value="user?.username"
:selected="ReadCurrentAlt() === user?.username"
>{{ user?.username }}
</option>
<option
v-for="(alt, index) in user?.alts"
:key="index"
:value="alt"
:selected="ReadCurrentAlt() === alt"
>
{{ alt }}
</option>
</select>
</div>
</div>
<div
v-if="isFetching && !user"
class="logged fetching"
Expand All @@ -19,27 +42,7 @@
</div>
<p />
</div>
<!--suppress TypeScriptUnresolvedReference -->
<!-- <div v-if="user.alts" class="select">-->
<div
v-if="user?.alts && user?.alts?.length!==0"
class="select"
>
<select @change="(e) => selectUserAlts(e.target.value)">
<option
:value="user?.username"
:selected="ReadCurrentAlt() === user?.username"
>{{ user?.username }}</option>
<option
v-for="(alt, index) in user?.alts"
:key="index"
:value="alt"
:selected="ReadCurrentAlt() === alt"
>
{{ alt }}
</option>
</select>
</div>
<div
v-if="user"
class="logged"
Expand Down Expand Up @@ -106,6 +109,16 @@
target="_blank"
>HS Compendium</a>
<div class="select switch-client">
<select
v-model="defaultSwitchClient"
@change="selectClient($event.target.value)"
>
<option :value="0">Default client</option>
<option :value="1">Client from Mentalisit</option>
</select>
</div>
<div
class="code-req-btn-wrap"
:class="{'disable': isFetching}"
Expand All @@ -128,8 +141,9 @@ import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Identity, User, Guild } from 'bot_client';
import { Identity as Identity2, User as User2, Guild as Guild2 } from 'bot_client2';
import client, { init as clientInit } from '@Utils/compendium';
import client, { init as clientInit, switchInstance } from '@Utils/compendium';
import { getDiscordAvatarUrl, getDiscordIconUrl } from '@Utils/getDiscordUrl';
import memberImage from '@Img/icons/member.png';
import types from '@/store/types';
Expand All @@ -146,8 +160,9 @@ const openCodeReqModal = ref(false);
const reqCode = ref('');
const error = ref('');
const isFetching = ref(false);
const user = ref<User|null>();
const guild = ref<Guild>();
const user = ref<User|User2|null>();
const guild = ref<Guild|Guild2>();
const defaultSwitchClient = ref(0);
onMounted(async () => {
isFetching.value = true;
Expand All @@ -163,14 +178,17 @@ onMounted(async () => {
// noinspection ES6MissingAwait
applyReqCode();
}
if ('client' in router.currentRoute.value.query) {
defaultSwitchClient.value = Number(router.currentRoute.value.query.client);
}
} else {
user.value = u;
guild.value = client.getGuild();
}
});
async function applyReqCode() {
let ident: Identity;
let ident: Identity|Identity2;
if (!reqCode.value) {
error.value = t('CANNOT_BE_EMPTY');
Expand Down Expand Up @@ -209,16 +227,22 @@ async function applyReqCode() {
}
}
function selectUserAlts(name: string) {
const u = client.getUser();
if (u?.username === name) {
localStorage.setItem('currentAlt', '' );
} else {
localStorage.setItem('currentAlt', name);
}
window.location.reload();
const u = client.getUser();
if (u?.username === name) {
localStorage.setItem('currentAlt', '' );
} else {
localStorage.setItem('currentAlt', name);
}
}
function ReadCurrentAlt():string {
return localStorage.getItem('currentAlt') || '';
return localStorage.getItem('currentAlt') || '';
}
function selectClient(value: number) {
isFetching.value = true;
switchInstance(value);
clientInit().then(() => {
isFetching.value = false;
});
}
function userProfileClick() {
store.dispatch(types.OPEN_CONFIRM, t('TID_SETTINGS_DLG_SIGN_OUT'))
Expand Down Expand Up @@ -248,6 +272,10 @@ function userProfileClick() {
justify-content: space-between;
align-items: center;
.alt-switch {
width: 110%;
}
@media screen and (max-width: 1000px){
margin: 0 1%;
}
Expand Down Expand Up @@ -353,6 +381,10 @@ function userProfileClick() {
margin-left: 10px;
font-style: italic;
}
.switch-client {
padding-top: 4%;
font-size: 80%;
}
@keyframes bg-pos-move {
to { background-position: 1000% 0; }
Expand Down
27 changes: 20 additions & 7 deletions src/utils/compendium.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import { Compendium as Client1 } from 'bot_client';
import { Compendium as Client2 } from 'bot_client2';
import store from '../../src/store/index';

function getClient() {
const useClient2 = 1 === 1; // store.state.userSettings.disableFilters; // нужно где то что то придумать вместо фильтра
return useClient2 ? new Client2() : new Client1();
}
const clients = [Client1, Client2];

const client = getClient();
let initialized = false;
let client: Client1|Client2 = new Client1();

const compendiumClient = localStorage.getItem('compendium_client');
if (compendiumClient) {
switchInstance(parseInt(compendiumClient));
}

export default client;
export default new Proxy(client, {
get(target: Client1 | Client2, p: string | symbol): unknown {
return client[p];
},
});

export async function init() {
if (!initialized) {
console.log(client);
await client.initialize();
initialized = true;
}
}

export function stop() {
client.shutdown();
initialized = false;
}

export function switchInstance(clientNum: number) {
stop();
client = new clients[clientNum]();
localStorage.setItem('compendium_client', String(clientNum));
}

0 comments on commit 5a393c4

Please sign in to comment.