-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup release notes logic on the client
- Loading branch information
Showing
21 changed files
with
658 additions
and
189 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { RELEASE_NOTES_DATA } from 'global'; | ||
import memoize from 'memoizerific'; | ||
|
||
import { ModuleFn, State } from '../index'; | ||
|
||
export interface ReleaseNotes { | ||
success?: boolean; | ||
currentVersion?: string; | ||
showOnFirstLaunch?: boolean; | ||
} | ||
|
||
const getReleaseNotesData = memoize(1)( | ||
(): ReleaseNotes => { | ||
try { | ||
return { ...(JSON.parse(RELEASE_NOTES_DATA) || {}) }; | ||
} catch (e) { | ||
return {}; | ||
} | ||
} | ||
); | ||
|
||
export interface SubAPI { | ||
releaseNotesVersion: () => string; | ||
showReleaseNotesOnLaunch: () => Promise<boolean>; | ||
} | ||
|
||
export const init: ModuleFn = ({ fullAPI, store }) => { | ||
let initStoreState: Promise<State[]>; | ||
const releaseNotesData = getReleaseNotesData(); | ||
|
||
const api: SubAPI = { | ||
releaseNotesVersion: () => releaseNotesData.currentVersion, | ||
showReleaseNotesOnLaunch: async () => { | ||
// Make sure any consumers of this function's return value have waited for | ||
// this module's state to have been setup. Otherwise, it may be called | ||
// before the store state is set and therefore have inaccurate data. | ||
await initStoreState; | ||
const { showReleaseNotesOnLaunch } = store.getState(); | ||
return showReleaseNotesOnLaunch; | ||
}, | ||
}; | ||
|
||
const initModule = () => { | ||
const { releaseNotesViewed: persistedReleaseNotesViewed } = store.getState(); | ||
let releaseNotesViewed = persistedReleaseNotesViewed || []; | ||
const didViewReleaseNotes = releaseNotesViewed.includes(releaseNotesData.currentVersion); | ||
const showReleaseNotesOnLaunch = releaseNotesData.showOnFirstLaunch && !didViewReleaseNotes; | ||
|
||
if (showReleaseNotesOnLaunch) { | ||
releaseNotesViewed = [...releaseNotesViewed, releaseNotesData.currentVersion]; | ||
} | ||
|
||
initStoreState = Promise.all([ | ||
store.setState({ showReleaseNotesOnLaunch }), | ||
store.setState({ releaseNotesViewed }, { persistence: 'permanent' }), | ||
]); | ||
}; | ||
|
||
return { init: initModule, api }; | ||
}; |
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,49 @@ | ||
import { ModuleFn } from '../index'; | ||
|
||
export interface SubAPI { | ||
changeSettingsTab: (tab: string) => void; | ||
closeSettings: () => void; | ||
isSettingsScreenActive: () => boolean; | ||
navigateToSettingsPage: (path: string) => Promise<void>; | ||
} | ||
|
||
export const init: ModuleFn = ({ store, navigate, fullAPI }) => { | ||
const isSettingsScreenActive = () => { | ||
const { path } = fullAPI.getUrlState(); | ||
return !!(path || '').match(/^\/settings/); | ||
}; | ||
const api: SubAPI = { | ||
closeSettings: () => { | ||
const { | ||
settings: { lastTrackedStoryId }, | ||
} = store.getState(); | ||
|
||
if (lastTrackedStoryId) { | ||
fullAPI.selectStory(lastTrackedStoryId); | ||
} else { | ||
fullAPI.selectFirstStory(); | ||
} | ||
}, | ||
changeSettingsTab: (tab: string) => { | ||
navigate(`/settings/${tab}`); | ||
}, | ||
isSettingsScreenActive, | ||
navigateToSettingsPage: async (path) => { | ||
if (!isSettingsScreenActive()) { | ||
const { settings, storyId } = store.getState(); | ||
|
||
await store.setState({ | ||
settings: { ...settings, lastTrackedStoryId: storyId }, | ||
}); | ||
} | ||
|
||
navigate(path); | ||
}, | ||
}; | ||
|
||
const initModule = async () => { | ||
await store.setState({ settings: { lastTrackedStoryId: null } }); | ||
}; | ||
|
||
return { init: initModule, api }; | ||
}; |
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
Oops, something went wrong.