06-11-2019 05:02
06-11-2019 05:02
Hi, is it possible to create more than one setting page and to switch among them through buttons?
Best Answer06-11-2019 13:54
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
06-11-2019 13:54
Yes. Here are some snippets from something of mine. This is highly ugly, but does work. For greater elegance and maintainability, think of your settings page as a state machine and centralise responsibility for setting the relevant menu-control settings when changing states.
<Page>
{props.settings.menu === 'false' ? null : (
<Section title={
<Text bold align="center">
MENU
</Text>
}>
<Button
label="Defaults"
onClick={() => {
props.settingsStorage.setItem('menu', 'false');
props.settingsStorage.setItem('defaults', 'true');
props.settingsStorage.setItem('slideSettings', 'false');
props.settingsStorage.setItem('editSlide', 'false');
props.settingsStorage.setItem('deleteSlide', 'false');
}}
/>
{slides.length>=MAX_SLIDES? null : (
<Button
label="Add a slide"
onClick={() => {
props.settingsStorage.setItem('menu', 'false');
props.settingsStorage.setItem('slideSettings', 'true');
}}
/>
)}
... {props.settings.defaults === 'false' ? null : (
<Section title={
<Text bold align="center">
Defaults
</Text>
}>
<Button
label="Back to menu"
onClick={() => {
props.settingsStorage.setItem('menu', 'true');
props.settingsStorage.setItem('defaults', 'false');
}}
/>
</Section>
)}
{props.settings.slideSettings === 'false' ? null : (
<Section title={
<Text bold align="center">
Slide Settings
</Text>
}>
...
Best Answer06-13-2019 00:44
06-13-2019 00:44
Hi and thanks for the answer! Your solution seems to work, even if i can't properly run your example.
What i've done yesterday is create a function at the event onClick on the back button that call registerSettingsPage with the menu page as argument. Something like this:
Best Answer06-13-2019 00:53
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
06-13-2019 00:53
I never thought of that, and had no idea that it would work. It could well lead to better-structured code than my spaghetti-laden mess.
Best Answer