-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73c9433
commit 530c277
Showing
14 changed files
with
75 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
declare module '@component-controls/loader/story-store-data'; | ||
declare module '@analytics/google-analytics'; | ||
declare module '@component-controls/webpack-compile/bundle'; |
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,34 @@ | ||
import { useMemo, useEffect } from 'react'; | ||
|
||
import Analytics from 'analytics'; | ||
import googleAnalytics from '@analytics/google-analytics'; | ||
|
||
import { StoryStore } from '@component-controls/store'; | ||
|
||
export const useAnalytics = (store: StoryStore) => { | ||
const analytics = useMemo(() => { | ||
if (store) { | ||
const options = store.config?.analytics; | ||
if (options) { | ||
if (typeof options === 'string') { | ||
return Analytics({ | ||
app: store.config?.siteTitle, | ||
plugins: [ | ||
googleAnalytics({ | ||
trackingId: options, | ||
}), | ||
], | ||
}); | ||
} else { | ||
return Analytics(options); | ||
} | ||
} | ||
} | ||
return undefined; | ||
}, [store]); | ||
useEffect(() => { | ||
if (analytics) { | ||
analytics.page(); | ||
} | ||
}, [analytics]); | ||
}; |
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 @@ | ||
declare module '@analytics/google-analytics'; |
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { atom, useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { StoryStore } from '@component-controls/store'; | ||
import { Document, PackageInfo } from '@component-controls/core'; | ||
|
||
export const storeAtom = atom<StoryStore | null>({ | ||
key: 'storyStore', // unique ID (with respect to other atoms/selectors) | ||
default: null, // default value (aka initial value) | ||
export type DocumentAtom = Document & { package?: PackageInfo }; | ||
|
||
export const documentAtom = atom<DocumentAtom | undefined>({ | ||
key: 'document', | ||
default: undefined, | ||
}); | ||
|
||
export const useStore = (): StoryStore => { | ||
const store = useRecoilValue(storeAtom); | ||
if (store === null) { | ||
throw new Error('You can not access store before assigning it'); | ||
} | ||
return store; | ||
export const useDocument = (): DocumentAtom | undefined => { | ||
const doc = useRecoilValue(documentAtom); | ||
return doc; | ||
}; | ||
|
||
export const setStore = (store: StoryStore) => | ||
useSetRecoilState(storeAtom)(store); | ||
export const setDocument = (doc: DocumentAtom) => | ||
useSetRecoilState(documentAtom)(doc); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './block'; | ||
export * from './components'; | ||
export * from './story'; | ||
export * from './block/storeState'; |