generated from PrithvirajMazumder/react-tailwind-daisyui-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
share words and view current word count
- Loading branch information
1 parent
fe60b42
commit cfe44dd
Showing
9 changed files
with
139 additions
and
16 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
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,7 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { words } from '../../store/game' | ||
|
||
export const WordCount = () => { | ||
const wordCount = useAtomValue(words).length | ||
return <div className="absolute top-[24px] z-20 text-sm">Word #{wordCount + 1}</div> | ||
} |
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,32 @@ | ||
import JSURL from 'jsurl' | ||
|
||
export const encodeResults = (data: { letters: string[]; words: string[] }) => { | ||
const encodedWords = data.words.map((word) => { | ||
return word.split('').map((letter) => { | ||
return data.letters.indexOf(letter) | ||
}) | ||
}) | ||
|
||
// Encode JSON into url friendly | ||
return JSURL.stringify({ | ||
w: encodedWords, | ||
l: data.letters | ||
}) | ||
} | ||
|
||
export const decodeResults = (encoded: string) => { | ||
const decoded = JSURL.parse<{ w: number[][]; l: string[] }>(decodeURIComponent(encoded)) | ||
|
||
const words = decoded.w.map((word: number[]) => { | ||
return word | ||
.map((index) => { | ||
return decoded.l[index] | ||
}) | ||
.join('') | ||
}) | ||
|
||
return { | ||
letters: decoded.l, | ||
words | ||
} | ||
} |
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