forked from FoundKeyGang/FoundKey
refactor: classic.sidebar.vue to composition api
This commit is contained in:
parent
3345b4efe1
commit
4fcbf3af36
1 changed files with 64 additions and 88 deletions
|
@ -1,34 +1,34 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="npcljfve" :class="{ iconOnly }">
|
<div ref="sidebar" class="npcljfve" :class="{ iconOnly }">
|
||||||
<button v-click-anime class="item _button account" @click="openAccountMenu">
|
<button v-if="$i" v-click-anime class="item _button account" @click="openAccountMenuWrapper">
|
||||||
<MkAvatar :user="$i" class="avatar"/><MkAcct class="text" :user="$i"/>
|
<MkAvatar :user="$i" class="avatar"/><MkAcct class="text" :user="$i"/>
|
||||||
</button>
|
</button>
|
||||||
<div class="post" data-cy-open-post-form @click="post">
|
<div class="post" data-cy-open-post-form @click="post">
|
||||||
<MkButton class="button" gradate full rounded>
|
<MkButton class="button" gradate full rounded>
|
||||||
<i class="fas fa-pencil-alt fa-fw"></i><span v-if="!iconOnly" class="text">{{ $ts.note }}</span>
|
<i class="fas fa-pencil-alt fa-fw"></i><span v-if="!iconOnly" class="text">{{ i18n.ts.note }}</span>
|
||||||
</MkButton>
|
</MkButton>
|
||||||
</div>
|
</div>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<MkA v-click-anime class="item index" active-class="active" to="/" exact>
|
<MkA v-click-anime class="item index" active-class="active" to="/" exact>
|
||||||
<i class="fas fa-home fa-fw"></i><span class="text">{{ $ts.timeline }}</span>
|
<i class="fas fa-home fa-fw"></i><span class="text">{{ i18n.ts.timeline }}</span>
|
||||||
</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 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 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 class="text">{{ $ts[menuDef[item].title] }}</span>
|
<i class="fa-fw" :class="menuDef[item].icon"></i><span class="text">{{ i18n.ts[menuDef[item].title] }}</span>
|
||||||
<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 class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
|
<MkA v-if="adminOrModerator" v-click-anime class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
|
||||||
<i class="fas fa-door-open fa-fw"></i><span class="text">{{ $ts.controlPanel }}</span>
|
<i class="fas fa-door-open fa-fw"></i><span class="text">{{ i18n.ts.controlPanel }}</span>
|
||||||
</MkA>
|
</MkA>
|
||||||
<button v-click-anime class="item _button" @click="more">
|
<button v-click-anime class="item _button" @click="more">
|
||||||
<i class="fas fa-ellipsis-h fa-fw"></i><span class="text">{{ $ts.more }}</span>
|
<i class="fas fa-ellipsis-h fa-fw"></i><span class="text">{{ i18n.ts.more }}</span>
|
||||||
<span v-if="otherNavItemIndicated" class="indicator"><i class="fas fa-circle"></i></span>
|
<span v-if="otherNavItemIndicated" class="indicator"><i class="fas fa-circle"></i></span>
|
||||||
</button>
|
</button>
|
||||||
<MkA v-click-anime class="item" active-class="active" to="/settings" :behavior="settingsWindowed ? 'modalWindow' : null">
|
<MkA v-click-anime class="item" active-class="active" to="/settings" :behavior="settingsWindowed ? 'modalWindow' : null">
|
||||||
<i class="fas fa-cog fa-fw"></i><span class="text">{{ $ts.settings }}</span>
|
<i class="fas fa-cog fa-fw"></i><span class="text">{{ i18n.ts.settings }}</span>
|
||||||
</MkA>
|
</MkA>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="about">
|
<div class="about">
|
||||||
|
@ -36,103 +36,79 @@
|
||||||
<img :src="$instance.iconUrl || $instance.faviconUrl || '/favicon.ico'" class="_ghost"/>
|
<img :src="$instance.iconUrl || $instance.faviconUrl || '/favicon.ico'" class="_ghost"/>
|
||||||
</MkA>
|
</MkA>
|
||||||
</div>
|
</div>
|
||||||
<!--<MisskeyLogo class="misskey"/>-->
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, defineComponent } from 'vue';
|
import { defineAsyncComponent, watch, defineEmits, onMounted, nextTick } 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 } from '@/account';
|
||||||
import MkButton from '@/components/ui/button.vue';
|
import MkButton from '@/components/ui/button.vue';
|
||||||
import { StickySidebar } from '@/scripts/sticky-sidebar';
|
import { StickySidebar } from '@/scripts/sticky-sidebar';
|
||||||
//import MisskeyLogo from '@assets/client/misskey.svg';
|
import { defaultStore } from '@/store';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let iconOnly = $ref(false);
|
||||||
components: {
|
let settingsWindowed = $ref(false);
|
||||||
MkButton,
|
let sidebar: HTMLElement | null = $ref(null);
|
||||||
//MisskeyLogo,
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
const menu = $computed(() => defaultStore.state.menu);
|
||||||
return {
|
const otherNavItemIndicated = $computed(() => {
|
||||||
host: host,
|
for (const def in menuDef) {
|
||||||
accounts: [],
|
if (menu.includes(def)) continue;
|
||||||
connection: null,
|
if (menuDef[def].indicated) return true;
|
||||||
menuDef: menuDef,
|
}
|
||||||
iconOnly: false,
|
return false;
|
||||||
settingsWindowed: false,
|
});
|
||||||
};
|
const adminOrModerator = $computed(() => $i && ($i.isAdmin || $i.isModerator));
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
const emit = defineEmits<{
|
||||||
menu(): string[] {
|
(ev: 'change-view-mode'): void;
|
||||||
return this.$store.state.menu;
|
}>();
|
||||||
},
|
|
||||||
|
|
||||||
otherNavItemIndicated(): boolean {
|
watch(() => defaultStore.reactiveState.menuDisplay.value, () => {
|
||||||
for (const def in this.menuDef) {
|
calcViewState();
|
||||||
if (this.menu.includes(def)) continue;
|
});
|
||||||
if (this.menuDef[def].indicated) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch(iconOnly, () => {
|
||||||
'$store.reactiveState.menuDisplay.value'() {
|
nextTick(() => {
|
||||||
this.calcViewState();
|
emit('change-view-mode');
|
||||||
},
|
});
|
||||||
|
});
|
||||||
|
|
||||||
iconOnly() {
|
onMounted(() => {
|
||||||
this.$nextTick(() => {
|
if (sidebar && sidebar.parentElement) {
|
||||||
this.$emit('change-view-mode');
|
const sticky = new StickySidebar(sidebar.parentElement, 16);
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
created() {
|
|
||||||
window.addEventListener('resize', this.calcViewState);
|
|
||||||
this.calcViewState();
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted() {
|
|
||||||
const sticky = new StickySidebar(this.$el.parentElement, 16);
|
|
||||||
window.addEventListener('scroll', () => {
|
window.addEventListener('scroll', () => {
|
||||||
sticky.calc(window.scrollY);
|
sticky.calc(window.scrollY);
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
calcViewState() {
|
|
||||||
this.iconOnly = (window.innerWidth <= 1400) || (this.$store.state.menuDisplay === 'sideIcon');
|
|
||||||
this.settingsWindowed = (window.innerWidth > 1400);
|
|
||||||
},
|
|
||||||
|
|
||||||
post() {
|
|
||||||
os.post();
|
|
||||||
},
|
|
||||||
|
|
||||||
search() {
|
|
||||||
search();
|
|
||||||
},
|
|
||||||
|
|
||||||
more(ev) {
|
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
|
|
||||||
src: ev.currentTarget ?? ev.target,
|
|
||||||
}, {}, 'closed');
|
|
||||||
},
|
|
||||||
|
|
||||||
openAccountMenu: (ev) => {
|
|
||||||
openAccountMenu({
|
|
||||||
withExtraOperation: true,
|
|
||||||
}, ev);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function calcViewState(): void {
|
||||||
|
iconOnly = (window.innerWidth <= 1400) || (defaultStore.state.menuDisplay === 'sideIcon');
|
||||||
|
settingsWindowed = (window.innerWidth > 1400);
|
||||||
|
}
|
||||||
|
|
||||||
|
function post(): void {
|
||||||
|
os.post();
|
||||||
|
}
|
||||||
|
|
||||||
|
function more(ev: { currentTarget: any; target: any; }): void {
|
||||||
|
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
|
||||||
|
src: ev.currentTarget ?? ev.target,
|
||||||
|
}, {}, 'closed');
|
||||||
|
}
|
||||||
|
|
||||||
|
function openAccountMenuWrapper(ev: MouseEvent): void {
|
||||||
|
openAccountMenu({
|
||||||
|
withExtraOperation: true,
|
||||||
|
}, ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', calcViewState);
|
||||||
|
calcViewState();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
Loading…
Reference in a new issue