client: refactor classic.header.vue to composition api #97

Merged
Johann150 merged 1 commit from refactor/client/classic.header.vue into main 2022-08-31 10:06:02 +00:00

View file

@ -7,13 +7,13 @@
</MkA>
<template v-for="item in menu">
<div v-if="item === '-'" class="divider"></div>
<component :is="menuDef[item].to ? 'MkA' : 'button'" v-else-if="menuDef[item] && (menuDef[item].show !== false)" v-click-anime v-tooltip="$ts[menuDef[item].title]" class="item _button" :class="item" active-class="active" :to="menuDef[item].to" v-on="menuDef[item].action ? { click: menuDef[item].action } : {}">
<component :is="menuDef[item].to ? 'MkA' : 'button'" v-else-if="menuDef[item] && (menuDef[item].show !== false)" v-click-anime v-tooltip="i18n.ts[menuDef[item].title]" class="item _button" :class="item" active-class="active" :to="menuDef[item].to" v-on="menuDef[item].action ? { click: menuDef[item].action } : {}">
<i class="fa-fw" :class="menuDef[item].icon"></i>
<span v-if="menuDef[item].indicated" class="indicator"><i class="fas fa-circle"></i></span>
</component>
</template>
<div class="divider"></div>
<MkA v-if="$i.isAdmin || $i.isModerator" v-click-anime v-tooltip="$ts.controlPanel" class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
<MkA v-if="iAmModerator" v-click-anime v-tooltip="i18n.ts.controlPanel" class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
<i class="fas fa-door-open fa-fw"></i>
</MkA>
<button v-click-anime class="item _button" @click="more">
@ -25,7 +25,7 @@
<MkA v-click-anime v-tooltip="$ts.settings" class="item" active-class="active" to="/settings" :behavior="settingsWindowed ? 'modalWindow' : null">
<i class="fas fa-cog fa-fw"></i>
</MkA>
<button v-click-anime class="item _button account" @click="openAccountMenu">
<button v-click-anime class="item _button account" @click="openAccountMenuWrapper">
<MkAvatar :user="$i" class="avatar"/><MkAcct class="acct" :user="$i"/>
</button>
<div class="post" @click="post">
@ -38,83 +38,52 @@
</div>
</template>
<script lang="ts">
import { defineAsyncComponent, defineComponent } from 'vue';
import { host } from '@/config';
import { search } from '@/scripts/search';
<script lang="ts" setup>
import { defineAsyncComponent, watch } from 'vue';
import * as os from '@/os';
import { menuDef } from '@/menu';
import { openAccountMenu } from '@/account';
import { openAccountMenu, $i, iAmModerator } from '@/account';
import MkButton from '@/components/ui/button.vue';
import { defaultStore } from '@/store';
import { i18n } from '@/i18n';
export default defineComponent({
components: {
MkButton,
},
let settingsWindowed = $ref(false);
data() {
return {
host,
accounts: [],
connection: null,
menuDef,
settingsWindowed: false,
};
},
computed: {
menu(): string[] {
return this.$store.state.menu;
},
otherNavItemIndicated(): boolean {
for (const def in this.menuDef) {
if (this.menu.includes(def)) continue;
if (this.menuDef[def].indicated) return true;
const menu = $computed(() => defaultStore.state.menu);
const otherNavItemIndicated = $computed((): boolean => {
for (const def in menuDef) {
if (menu.includes(def)) continue;
if (menuDef[def].indicated) return true;
}
return false;
},
},
});
watch: {
'$store.reactiveState.menuDisplay.value'() {
this.calcViewState();
},
},
function calcViewState(): void {
settingsWindowed = (window.innerWidth > 1400);
}
created() {
window.addEventListener('resize', this.calcViewState);
this.calcViewState();
},
watch(defaultStore.reactiveState.menuDisplay, calcViewState);
methods: {
calcViewState() {
this.settingsWindowed = (window.innerWidth > 1400);
},
window.addEventListener('resize', calcViewState);
calcViewState();
post() {
function post(): void {
os.post();
},
}
search() {
search();
},
more(ev) {
function more(ev: MouseEvent | TouchEvent): void {
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
src: ev.currentTarget ?? ev.target,
anchor: { x: 'center', y: 'bottom' },
}, {
}, 'closed');
},
}
openAccountMenu: (ev) => {
function openAccountMenuWrapper(ev: MouseEvent): void {
openAccountMenu({
withExtraOperation: true,
}, ev);
},
},
});
}
</script>
<style lang="scss" scoped>