Skip to content

Commit

Permalink
make pause during compact sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Sep 21, 2023
1 parent b7add14 commit d4afba4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
- put on google play store
- put on sect game site
- remove from word games and point to here instead
- fix safari styling -- url bar cuts off (check out the sector code for the new css)
- add way to share specific game
- make word game service worker update?

Maybe later

Expand Down
24 changes: 15 additions & 9 deletions src/components/ControlBar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import {handleInstall} from "../logic/handleInstall";
import Share from "./Share";
import {handleShare} from "./Share";

export default function ControlBar({
gameState,
Expand Down Expand Up @@ -56,14 +56,20 @@ export default function ControlBar({

<button id="heartButton" onClick={() => setDisplay("heart")}></button>

{navigator.canShare ? (
<Share
compact={true}
text={"Try out this Gribbles puzzle:"}
seed={`${gameState.seed}_${Math.sqrt(gameState.letters.length)}_${
gameState.minWordLength
}_${gameState.easyMode ? "e" : "h"}`}
/>
{!navigator.canShare ? (
<button
id="shareButton"
onClick={() => {
timerDispatch({action: "pause"});
setDisplay("pause");
handleShare({
text: "Try out this Gribbles puzzle:",
seed: `${gameState.seed}_${Math.sqrt(gameState.letters.length)}_${
gameState.minWordLength
}_${gameState.easyMode ? "e" : "h"}`,
});
}}
></button>
) : (
<></>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Heart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import Share from "./Share";
import {Share} from "./Share";
import packageJson from "../../package.json";

export default function Heart({setDisplay}) {
Expand Down
50 changes: 24 additions & 26 deletions src/components/Share.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import React from "react";
import sendAnalytics from "../logic/sendAnalytics";

function handleShare({text, fullUrl}) {
navigator
.share({
title: "Gribbles",
text: `${text}\n\n`,
url: fullUrl,
})
.then(() => console.log("Successful share"))
.catch((error) => {
// copy to clipboard as backup
handleCopy(text);
console.log("Error sharing", error);
});
export function handleShare({text, seed}) {
const url = "https://skedwards88.github.io/gribbles/";
const fullUrl = seed ? `${url}?puzzle=${seed}` : url;

if (navigator.canShare) {
navigator
.share({
title: "Gribbles",
text: `${text}\n\n`,
url: fullUrl,
})
.then(() => console.log("Successful share"))
.catch((error) => {
// copy to clipboard as backup
handleCopy({text, fullUrl});
console.log("Error sharing", error);
});
} else {
handleCopy({text, fullUrl});
}

sendAnalytics("share");
}

Expand All @@ -25,20 +33,10 @@ function handleCopy({text, fullUrl}) {
}
}

export default function Share({text, seed, compact = false}) {
const url = "https://skedwards88.github.io/gribbles/";
const fullUrl = seed ? `${url}?puzzle=${seed}` : url;

export function Share({text, seed}) {
return (
<button
id={compact ? "shareButton" : ""}
onClick={() =>
navigator.canShare
? handleShare({text, fullUrl})
: handleCopy({text, fullUrl})
}
>
{compact ? "" : navigator.canShare ? "Share" : "Copy link to share"}
<button onClick={() => handleShare({text, seed})}>
{navigator.canShare ? "Share" : "Copy link to share"}
</button>
);
}

0 comments on commit d4afba4

Please sign in to comment.