Skip to content

Commit 86989a2

Browse files
committed
Shared is fixed and works!
1 parent 687fdda commit 86989a2

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
/build
3-
/*.log
3+
/*.log
4+
.DS_Store

src/components/Share.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useCallback, useContext } from "preact/hooks";
33
import { GameContext } from "../game/provider";
44

55
const convertTip = (row) => {
6-
return Array.from({ length: 6 })
6+
return Array.from({ length: 5 })
77
.map((_, i) => {
88
if (row[i] && row[i].isExact) {
99
return "🟩";
@@ -18,23 +18,36 @@ const convertTip = (row) => {
1818

1919
export const Share = () => {
2020
const { gameover, tips } = useContext(GameContext);
21-
const result = tips.map(convertTip).join("\n");
21+
const table = tips.map(convertTip);
22+
const result = table
23+
.slice(0, table.findIndex((row) => row === "🟩🟩🟩🟩🟩") + 1)
24+
.join("\n");
25+
const text = `Қазақша Wordle!\n\n${result}\n\nhttps://wordle.jarjan.xyz`;
2226

23-
const handleClick = useCallback(() => {
24-
if (navigator.share) {
25-
navigator.share({
26-
title: `Қазақша Wordle!\n${result}\nhttps://wordle.jarjan.xyz`,
27-
});
27+
const handleCopy = useCallback(() => {
28+
if (navigator.clipboard) {
29+
navigator.clipboard.writeText(text);
2830
}
2931
}, [tips]);
3032

31-
if (!gameover || !navigator.share) return null;
33+
if (!gameover) return null;
3234

3335
return (
3436
<div class="share">
35-
<button type="button" onClick={handleClick}>
36-
Нәтижемен бөліс!
37-
</button>
37+
{navigator.clipboard && (
38+
<button class="share__button" type="button" onClick={handleCopy}>
39+
Нәтижені көшіріп алу
40+
</button>
41+
)}
42+
<a
43+
class="share__button"
44+
href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(
45+
text
46+
)}`}
47+
target="_blank"
48+
>
49+
Твиттерге бөлісу
50+
</a>
3851
</div>
3952
);
4053
};

src/style.css

+17-4
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ body {
6464

6565
.keyboard__key.correct,
6666
.board__tile.correct {
67-
background-color: #e1c73d;
67+
background-color: #fbff00;
6868
}
6969

7070
.keyboard__key.exact,
7171
.board__tile.exact {
72-
background-color: rgb(113, 155, 49);
72+
background-color: #c9e265;
7373
}
7474

7575
.keyboard {
@@ -118,7 +118,7 @@ body {
118118
.toast {
119119
position: absolute;
120120
margin: 20px auto;
121-
background: rgba(4, 62, 255, 0.9);
121+
background: rgba(201, 226, 101, 0.9);
122122
color: white;
123123
padding: 10px;
124124
border-radius: 10px;
@@ -136,11 +136,24 @@ body {
136136

137137
.share {
138138
padding: 20px 0;
139+
display: flex;
140+
gap: 20px;
139141
}
140142

141-
.share button {
143+
.share__button {
144+
background: none;
145+
border: 2px solid rgba(201, 226, 101, 0.9);
146+
color: #c9e265;
142147
display: block;
143148
margin: auto;
144149
font-size: 30px;
145150
padding: 10px 30px;
151+
text-decoration: none;
152+
text-align: center;
153+
cursor: pointer;
154+
transition: all 300ms ease-in-out;
155+
}
156+
.share__button:hover {
157+
background-color: #c9e265;
158+
color: white;
146159
}

0 commit comments

Comments
 (0)