summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2022-04-23 19:17:15 +0900
committerGitHub <noreply@github.com>2022-04-23 19:17:15 +0900
commiteac71ae1d7f7d1ee4c06c4060979b7b292c0e57e (patch)
treed97a10506033d82f0d439c6111978d346e617800 /packages/client/src/scripts
parentchore: fix lint command for windows (diff)
downloadsharkey-eac71ae1d7f7d1ee4c06c4060979b7b292c0e57e.tar.gz
sharkey-eac71ae1d7f7d1ee4c06c4060979b7b292c0e57e.tar.bz2
sharkey-eac71ae1d7f7d1ee4c06c4060979b7b292c0e57e.zip
fix: Fix settings page (#8508)
* Fix settings page * nanka iroiro * clean up * clean up * インデックスに戻ってもタイトルが残ってしまうのを修正
Diffstat (limited to 'packages/client/src/scripts')
-rw-r--r--packages/client/src/scripts/navigate.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/client/src/scripts/navigate.ts b/packages/client/src/scripts/navigate.ts
new file mode 100644
index 0000000000..08b891ec5b
--- /dev/null
+++ b/packages/client/src/scripts/navigate.ts
@@ -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);
+ }
+ }
+ }
+}