forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pari Plus add max history pages limit
- Loading branch information
1 parent
2b0cdd7
commit 96f1348
Showing
6 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Router } from 'vue-router'; | ||
import { defaultStore } from '@/store.js'; | ||
import { watch } from 'vue'; | ||
|
||
export class HistoryManager { | ||
private history: string[] = []; | ||
|
||
constructor(private router: Router) { | ||
this.setupHistoryManagement(); | ||
} | ||
|
||
private get maxHistory(): number { | ||
return defaultStore.state.maxHistoryPages ?? 5; | ||
} | ||
|
||
private setupHistoryManagement() { | ||
this.router.beforeEach((to, from, next) => { | ||
if (from.path !== to.path) { | ||
this.addToHistory(to.path); | ||
} | ||
next(); | ||
}); | ||
|
||
const originalPushState = history.pushState; | ||
history.pushState = (...args) => { | ||
if (this.history.length >= this.maxHistory) { | ||
this.history.shift(); | ||
} | ||
return originalPushState.apply(history, args); | ||
}; | ||
|
||
watch( | ||
() => defaultStore.state.maxHistoryPages, | ||
(newMaxPages) => { | ||
if (newMaxPages && this.history.length > newMaxPages) { | ||
this.history = this.history.slice(-newMaxPages); | ||
} | ||
} | ||
); | ||
} | ||
|
||
private addToHistory(path: string) { | ||
if (this.history.length >= this.maxHistory) { | ||
this.history.shift(); | ||
} | ||
this.history.push(path); | ||
} | ||
|
||
public getHistoryLength(): number { | ||
return this.history.length; | ||
} | ||
|
||
public clearHistory(): void { | ||
this.history = []; | ||
} | ||
|
||
public getMaxHistory(): number { | ||
return this.maxHistory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters