-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #500 from cofacts/typescript
Initialize Typescript
- Loading branch information
Showing
25 changed files
with
8,462 additions
and
628 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 |
---|---|---|
|
@@ -12,3 +12,5 @@ | |
!ecosystem.config.js | ||
!.storybook/* | ||
!public/* | ||
!pages/* | ||
!typegen/* |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CodegenConfig } from '@graphql-codegen/cli'; | ||
|
||
const config: CodegenConfig = { | ||
// schema: 'http://localhost:5000/graphql', | ||
schema: 'https://dev-api.cofacts.tw/graphql', | ||
documents: ['pages/**/*.tsx?', 'components/**/*.tsx?', 'lib/**/*.tsx'], | ||
generates: { | ||
'./typegen/': { | ||
preset: 'client', | ||
plugins: [], | ||
presetConfig: { | ||
// Rename useFragment to avoid conflicting with ESLint React hook rule | ||
// https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#embrace-fragment-masking-principles | ||
fragmentMasking: { unmaskFunctionName: 'getFragmentData' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
export default config; |
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
import { useEffect } from 'react'; | ||
|
||
/** | ||
* Google tag manager related utility functions | ||
*/ | ||
|
||
/** | ||
* @param args - data to feed to dataLayer.push | ||
*/ | ||
export function pushToDataLayer(...args: unknown[]) { | ||
if (typeof window === 'undefined') return; // Skip in SSR | ||
|
||
if (!('dataLayer' in window)) window['dataLayer'] = []; | ||
window['dataLayer'].push(...args); | ||
} | ||
|
||
/** | ||
* @param trigger - trigger useEffect() after trigger turns truthy | ||
* @param args - data to send to pushDataLayer on trigger change | ||
*/ | ||
export function usePushToDataLayer(trigger: unknown, args: object) { | ||
const dontTrigger = !trigger; | ||
useEffect(() => { | ||
if (dontTrigger) return; | ||
pushToDataLayer(args); | ||
}, [dontTrigger, args]); | ||
} |
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.