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> </MkA>
<template v-for="item in menu"> <template v-for="item in menu">
<div v-if="item === '-'" class="divider"></div> <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> <i class="fa-fw" :class="menuDef[item].icon"></i>
<span v-if="menuDef[item].indicated" class="indicator"><i class="fas fa-circle"></i></span> <span v-if="menuDef[item].indicated" class="indicator"><i class="fas fa-circle"></i></span>
</component> </component>
</template> </template>
<div class="divider"></div> <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> <i class="fas fa-door-open fa-fw"></i>
</MkA> </MkA>
<button v-click-anime class="item _button" @click="more"> <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"> <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> <i class="fas fa-cog fa-fw"></i>
</MkA> </MkA>
<button v-click-anime class="item _button account" @click="openAccountMenu"> <button v-click-anime class="item _button account" @click="openAccountMenuWrapper">
norm marked this conversation as resolved Outdated

I don't think checking for $i is necessary here, since this component is intended for classic UI which is only shown for logged in users. Visitors will only see the visitor UI.

I don't think checking for `$i` is necessary here, since this component is intended for classic UI which is only shown for logged in users. Visitors will only see the visitor UI.
<MkAvatar :user="$i" class="avatar"/><MkAcct class="acct" :user="$i"/> <MkAvatar :user="$i" class="avatar"/><MkAcct class="acct" :user="$i"/>
</button> </button>
<div class="post" @click="post"> <div class="post" @click="post">
@ -38,83 +38,52 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineAsyncComponent, defineComponent } from 'vue'; import { defineAsyncComponent, watch } from 'vue';
import { host } from '@/config';
import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import { menuDef } from '@/menu'; import { menuDef } from '@/menu';
import { openAccountMenu } from '@/account'; import { openAccountMenu, $i, iAmModerator } from '@/account';
norm marked this conversation as resolved Outdated

I think it would be nicer to rename the function thats defined here and import it with the correct name.

I think it would be nicer to rename the function thats defined here and import it with the correct name.
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import { defaultStore } from '@/store';
import { i18n } from '@/i18n';
export default defineComponent({ let settingsWindowed = $ref(false);
components: {
MkButton,
},
data() { const menu = $computed(() => defaultStore.state.menu);
return { const otherNavItemIndicated = $computed((): boolean => {
host, for (const def in menuDef) {
accounts: [], if (menu.includes(def)) continue;
connection: null, if (menuDef[def].indicated) return true;
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;
} }
return false; return false;
}, });
},
watch: { function calcViewState(): void {
'$store.reactiveState.menuDisplay.value'() { settingsWindowed = (window.innerWidth > 1400);
this.calcViewState(); }
},
},
created() { watch(defaultStore.reactiveState.menuDisplay, calcViewState);
window.addEventListener('resize', this.calcViewState);
this.calcViewState();
},
methods: { window.addEventListener('resize', calcViewState);
calcViewState() { calcViewState();
this.settingsWindowed = (window.innerWidth > 1400);
},
post() { function post(): void {
os.post(); os.post();
}, }
search() { function more(ev: MouseEvent | TouchEvent): void {
search();
},
more(ev) {
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), { os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
src: ev.currentTarget ?? ev.target, src: ev.currentTarget ?? ev.target,
anchor: { x: 'center', y: 'bottom' }, anchor: { x: 'center', y: 'bottom' },
}, { }, {
}, 'closed'); }, 'closed');
}, }
openAccountMenu: (ev) => { function openAccountMenuWrapper(ev: MouseEvent): void {
openAccountMenu({ openAccountMenu({
withExtraOperation: true, withExtraOperation: true,
}, ev); }, ev);
}, }
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>