-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Add sharing support #264
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a046614
add share utils
elcharitas 707ff6c
add test cases
elcharitas 09aa777
lint fix
elcharitas b41ae55
wip
elcharitas d337478
fixes
elcharitas 8355847
void button onClick
elcharitas d9dc247
add logging for share
elcharitas 13331a8
fixes
elcharitas 82e5c5a
cleanup
elcharitas 67b2e3d
Merge branch 'dev' into ALPHA-4678-share-button
elcharitas 61983a2
fix up lints issues
elcharitas a7c0543
Merge branch 'dev' into ALPHA-4678-share-button
v-almonacid 8153e04
Merge branch 'dev' into ALPHA-4678-share-button
elcharitas 7a1e1d9
fixes
elcharitas 0fbd643
Merge branch 'dev' into ALPHA-4678-share-button
elcharitas c401acb
more fixes
elcharitas 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
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,33 @@ | ||
import { canShare, shareData } from "./shareUtils"; | ||
|
||
describe("shareUtils", () => { | ||
describe("canShare", () => { | ||
it("should return true if the Web Share API is supported", () => { | ||
expect(canShare()).toBe(true); | ||
}); | ||
|
||
it("should return false if the Web Share API is not supported", () => { | ||
// @ts-expect-error navigator is read-only, we're just testing | ||
navigator.share = undefined; | ||
expect(canShare()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("shareData", () => { | ||
it("should share the provided data using the Web Share API", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
expect(shareData({ title: "Test", text: "Test" })).resolves.toBe( | ||
undefined | ||
); | ||
}); | ||
|
||
it("should not share the data if the Web Share API is not supported", () => { | ||
// @ts-expect-error navigator is read-only, we're just testing | ||
navigator.share = undefined; | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
expect(shareData({ title: "Test", text: "Test" })).rejects.toThrow( | ||
"Sharing not supported" | ||
); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
/** | ||
* Checks if the current environment supports the Web Share API. | ||
* | ||
* @returns Returns true if the Web Share API is supported, otherwise false. | ||
*/ | ||
export function canShare() { | ||
return navigator.share !== undefined && navigator.canShare !== undefined; | ||
} | ||
|
||
/** | ||
* Shares the provided data using the Web Share API if it is supported by the browser. | ||
* | ||
* @param data - The data to be shared. | ||
*/ | ||
export function shareData(data: ShareData) { | ||
if (canShare() && navigator.canShare(data)) { | ||
return navigator.share(data); | ||
} | ||
return Promise.reject(new Error("Sharing not supported")); | ||
} |
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
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.
Oops, something went wrong.
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.
weird that this is true during a test, which is run on node 🤔