Skip to content

Commit 437ac1e

Browse files
committed
fix: prevent back movement whenever tegaki is open.
1 parent 10f855f commit 437ac1e

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineStore } from 'pinia'
2+
3+
export const useTegakiViewStore = defineStore(
4+
'tegakiViewStore',
5+
{
6+
state: () => {
7+
return {
8+
pop: false
9+
}
10+
}
11+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Tegaki } from '@/api/tegaki/tegaki';
2+
import { useTegakiViewStore } from '@/api/tegaki/store'
3+
import type { Router } from 'vue-router'
4+
import i18next from 'i18next'
5+
6+
window.addEventListener('popstate', () => {
7+
const store = useTegakiViewStore();
8+
store.pop = true;
9+
});
10+
11+
export const withTegakiViewBackProtection = (router: Router) : void => {
12+
router.beforeEach((to, from) => {
13+
console.log(`visible ${Tegaki.visible}`)
14+
if (!Tegaki.visible) {
15+
return true;
16+
}
17+
18+
const confirm = window.confirm(i18next.t("tegakijs.confirmCancel"));
19+
if (confirm) {
20+
Tegaki.hide();
21+
return true;
22+
}
23+
24+
return false;
25+
});
26+
};

PinkSea.Frontend/src/api/tegaki/tegaki.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,8 @@ export var Tegaki = {
27012701

27022702
startTimeStamp: 0,
27032703

2704+
visible: false,
2705+
27042706
bg: null,
27052707
canvas: null,
27062708
ctx: null,
@@ -2846,6 +2848,8 @@ export var Tegaki = {
28462848
self.loadReplayFromURL(opts.replayURL);
28472849
}
28482850
}
2851+
2852+
self.visible = true;
28492853
},
28502854

28512855
init: function() {
@@ -3137,6 +3141,8 @@ export var Tegaki = {
31373141
Tegaki.bg.classList.add('tegaki-hidden');
31383142
document.body.classList.remove('tegaki-backdrop');
31393143
Tegaki.unBindGlobalEvents();
3144+
3145+
Tegaki.visible = false;
31403146
},
31413147

31423148
destroy: function() {
@@ -3171,6 +3177,8 @@ export var Tegaki = {
31713177
Tegaki.replayViewer = null;
31723178

31733179
Tegaki.destroyBuffers();
3180+
3181+
Tegaki.visible = false;
31743182
},
31753183

31763184
flatten: function(ctx) {

PinkSea.Frontend/src/router/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { xrpc } from '@/api/atproto/client'
99
import TagView from '@/views/TagView.vue'
1010
import SettingsView from '@/views/SettingsView.vue'
1111
import i18next from 'i18next'
12+
import { withTegakiViewBackProtection } from '@/api/tegaki/tegaki-view-helper'
1213

1314
const router = createRouter({
1415
history: createWebHistory(import.meta.env.BASE_URL),
@@ -84,5 +85,6 @@ const router = createRouter({
8485
});
8586

8687
withBreadcrumb(router);
88+
withTegakiViewBackProtection(router);
8789

8890
export default router

0 commit comments

Comments
 (0)