mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-21 05:29:31 -07:00
refactor(state.ts): extract logic to get threshold session index into a separate function for reusability and clarity
This commit is contained in:
3
.github/workflows/artifacts.yml
vendored
3
.github/workflows/artifacts.yml
vendored
@@ -65,6 +65,9 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: ESlint
|
||||||
|
run: pnpm run lint
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
pnpm run build
|
pnpm run build
|
||||||
|
|||||||
@@ -14,9 +14,19 @@ initNav()
|
|||||||
if (ijs.length > 0) {
|
if (ijs.length > 0) {
|
||||||
if (!isMobile()) {
|
if (!isMobile()) {
|
||||||
import('./desktop/init')
|
import('./desktop/init')
|
||||||
.then((d) => d.initDesktop(ijs))
|
.then((d) => {
|
||||||
.catch((e) => console.log(e))
|
d.initDesktop(ijs)
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
import('./mobile/init').then((m) => m.initMobile(ijs)).catch((e) => console.log(e))
|
import('./mobile/init')
|
||||||
|
.then((m) => {
|
||||||
|
m.initMobile(ijs)
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ const thresholds = [
|
|||||||
const defaultState = {
|
const defaultState = {
|
||||||
index: -1,
|
index: -1,
|
||||||
length: 0,
|
length: 0,
|
||||||
threshold:
|
threshold: thresholds[getThresholdSessionIndex()].threshold,
|
||||||
thresholds[parseInt(sessionStorage.getItem('thresholdsIndex') || '2')].threshold,
|
trailLength: thresholds[getThresholdSessionIndex()].trailLength
|
||||||
trailLength:
|
|
||||||
thresholds[parseInt(sessionStorage.getItem('thresholdsIndex') || '2')].trailLength
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const state = new Watchable<State>(defaultState)
|
export const state = new Watchable<State>(defaultState)
|
||||||
@@ -75,7 +73,7 @@ export function decThreshold(): void {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function updateThreshold(state: State, inc: number): State {
|
function updateThreshold(state: State, inc: number): State {
|
||||||
let i = thresholds.findIndex((t) => state.threshold === t.threshold) + inc
|
const i = thresholds.findIndex((t) => state.threshold === t.threshold) + inc
|
||||||
// out of bounds
|
// out of bounds
|
||||||
if (i < 0 || i >= thresholds.length) return state
|
if (i < 0 || i >= thresholds.length) return state
|
||||||
// storage the index so we can restore it even if we go to another page
|
// storage the index so we can restore it even if we go to another page
|
||||||
@@ -83,3 +81,9 @@ function updateThreshold(state: State, inc: number): State {
|
|||||||
const newItems = thresholds[i]
|
const newItems = thresholds[i]
|
||||||
return { ...state, ...newItems }
|
return { ...state, ...newItems }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getThresholdSessionIndex(): number {
|
||||||
|
const s = sessionStorage.getItem('thresholdsIndex')
|
||||||
|
if (s === null) return 2
|
||||||
|
return parseInt(s)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user