Created
June 22, 2021 14:28
-
-
Save josefrichter/2f7e4d4f80200819107fc0d9fd86e70c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const data = Data({ | |
ch1page: 1, | |
ch2page: 1, | |
ch3page: 1, | |
}) | |
const ch1times = [1000, 1100, 1200, 1300] | |
const ch2times = [1000, 1015, 1100, 1130] | |
const ch3times = [1000, 1015, 1030, 1130] | |
export function ChangeCh1Page(): Override { | |
return { | |
onChangePage: (newPageIndex, oldPageIndex) => { | |
console.log(newPageIndex) | |
data.ch1page = newPageIndex | |
const newTime = ch1times[newPageIndex] | |
updatePages(newTime) | |
}, | |
currentPage: data.ch1page, | |
} | |
} | |
export function ChangeCh2Page(): Override { | |
return { | |
onChangePage: (newPageIndex, oldPageIndex) => { | |
data.ch2page = newPageIndex | |
const newTime = ch2times[newPageIndex] | |
updatePages(newTime) | |
}, | |
currentPage: data.ch2page, | |
} | |
} | |
export function ChangeCh3Page(): Override { | |
return { | |
onChangePage: (newPageIndex, oldPageIndex) => { | |
data.ch3page = newPageIndex | |
const newTime = ch3times[newPageIndex] | |
updatePages(newTime) | |
}, | |
currentPage: data.ch3page, | |
} | |
} | |
function updatePages(newTime) { | |
data.ch1page = ch1times.findIndex((time) => time >= newTime) | |
data.ch2page = ch2times.findIndex((time) => time >= newTime) | |
data.ch3page = ch3times.findIndex((time) => time >= newTime) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment