-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Web Share API. #148
Open
enjikaka
wants to merge
8
commits into
impactmakers:master
Choose a base branch
from
enjikaka:feature/web-share-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1600ff6
Add information about having to install Gatsby CLI before running the…
enjikaka 51b08c4
Add new NativeShareButton component that uses the Web Share API.
enjikaka ca18a3a
Add jsconfig.json file to make TypeScript linter in VSCode not give f…
enjikaka 5ea60c4
Conditionally render the new NativeShareButton if the Web Share API i…
enjikaka af6aabc
Revert "Add information about having to install Gatsby CLI before run…
enjikaka ae04040
Scope navigator to window so that maybe the tests pass.
enjikaka 050dd86
Allow JSX in jsconfig.json. Ignore node_modules.
enjikaka ab58a24
Add `typeof window !== "undefined"` to webShareApi bool.
enjikaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"checkJs": true, | ||
"module": "esnext", | ||
"target": "es2019", | ||
"moduleResolution": "node", | ||
"jsx": "react" | ||
}, | ||
"exclude": ["node_modules", "**/node_modules/*"] | ||
} |
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,44 @@ | ||
import React from "react"; | ||
import styles from "./styles.module.scss"; | ||
import buttonStyles from "../../styles/Buttons.module.scss"; | ||
|
||
/** | ||
* @typedef Props | ||
* @prop {string} title | ||
* @prop {string} text | ||
* @prop {string} url | ||
*/ | ||
|
||
/** | ||
* Renders a button that opens the Web Share API dialog | ||
* with the, in Props, provided text, title and url. | ||
* | ||
* @param {Props} props | ||
*/ | ||
export default function NativeShareButton(props) { | ||
const { title, text, url } = props; | ||
|
||
async function openShareDialog() { | ||
try { | ||
await navigator.share({ | ||
title, | ||
text, | ||
url | ||
}); | ||
} catch (shareError) { | ||
// Handle share error maybe? | ||
// This would be trying to share on unsecure origins... | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<button | ||
className={`${styles.button} ${buttonStyles.btnSimple}`} | ||
onClick={openShareDialog} | ||
> | ||
Share | ||
</button> | ||
</> | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With JSDoc like this and JS type checking enabled in VS Code this will give you errors when specifing props wrongly or adding props that doesn't exists. Kinda handy and no need to go in fully for TypeScript or Flow in the project. Could be progressively and selectively added. :)
Type checking could also be run with the TypeScript CLI in CI like so;
tsc -p jsconfig.json --noEmit