Merge branch 'develop' into vite
This commit is contained in:
commit
b2886b5ecb
21 changed files with 581 additions and 1305 deletions
34
packages/client/src/scripts/navigate.ts
Normal file
34
packages/client/src/scripts/navigate.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { inject } from 'vue';
|
||||
import { router } from '@/router';
|
||||
import { defaultStore } from '@/store';
|
||||
|
||||
export type Navigate = (path: string, record?: boolean) => void;
|
||||
|
||||
export class MisskeyNavigator {
|
||||
public readonly navHook: Navigate | null = null;
|
||||
public readonly sideViewHook: Navigate | null = null;
|
||||
|
||||
// It should be constructed during vue creating in order for inject function to work
|
||||
constructor() {
|
||||
this.navHook = inject<Navigate | null>('navHook', null);
|
||||
this.sideViewHook = inject<Navigate | null>('sideViewHook', null);
|
||||
}
|
||||
|
||||
// Use this method instead of router.push()
|
||||
public push(path: string, record = true) {
|
||||
if (this.navHook) {
|
||||
this.navHook(path, record);
|
||||
} else {
|
||||
if (defaultStore.state.defaultSideView && this.sideViewHook && path !== '/') {
|
||||
return this.sideViewHook(path, record);
|
||||
}
|
||||
|
||||
if (router.currentRoute.value.path === path) {
|
||||
window.scroll({ top: 0, behavior: 'smooth' });
|
||||
} else {
|
||||
if (record) router.push(path);
|
||||
else router.replace(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue