Skip to content

Commit

Permalink
chore: Clean up inconsistent exports
Browse files Browse the repository at this point in the history
There was a warning about Fast Refresh being broken because a file that
exported a component didn't **only** export components.
  • Loading branch information
evancharlton committed Oct 19, 2024
1 parent 8961ffb commit 8cc7227
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
38 changes: 2 additions & 36 deletions src/Game/Grid/Remainder/Remainder.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
import { useMemo } from "react";
import { useWords } from "../../../App/Setup/DataLoader";
import { useWord } from "../../../App/Setup/GameLoader";
import { getLegality } from "../../../utils";
import { useGuesses, useSettings } from "../../guess";
import { useGuesses } from "../../guess";
import classes from "./Remainder.module.css";

const format = (v: number) => {
if (v < 1_000) {
return v;
}
const thousands = Math.floor(v / 1000);
const hundreds = `000${v % 1000}`.substr(-3);
return `${thousands}${String.fromCharCode(0xa0)}${hundreds}`;
};

export const usePossibilities = (guesses: string[]) => {
const { showRemaining } = useSettings();

const words = useWords();
const word = useWord();
return useMemo(() => {
if (!showRemaining) {
return {
remainders: [],
formattedCount: format(0),
};
}

let filtered = [...words];
guesses.forEach((guess) => {
const test = getLegality(word, guess);
filtered = filtered.filter((w) => test(w) === "legal");
});
return { remainders: filtered, formattedCount: format(filtered.length) };
}, [guesses, showRemaining, word, words]);
};
import { usePossibilities } from "./usePossibilities";

const Remainder = () => {
const [guessMap] = useGuesses();
Expand Down
2 changes: 1 addition & 1 deletion src/Game/Grid/Remainder/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from "./Remainder";
export { usePossibilities } from "./Remainder";
export { usePossibilities } from "./usePossibilities";
36 changes: 36 additions & 0 deletions src/Game/Grid/Remainder/usePossibilities.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMemo } from "react";
import { useWords } from "../../../App/Setup/DataLoader";
import { useWord } from "../../../App/Setup/GameLoader";
import { getLegality } from "../../../utils";
import { useSettings } from "../../guess";

const format = (v: number) => {
if (v < 1_000) {
return v;
}
const thousands = Math.floor(v / 1000);
const hundreds = `000${v % 1000}`.substr(-3);
return `${thousands}${String.fromCharCode(0xa0)}${hundreds}`;
};

export const usePossibilities = (guesses: string[]) => {
const { showRemaining } = useSettings();

const words = useWords();
const word = useWord();
return useMemo(() => {
if (!showRemaining) {
return {
remainders: [],
formattedCount: format(0),
};
}

let filtered = [...words];
guesses.forEach((guess) => {
const test = getLegality(word, guess);
filtered = filtered.filter((w) => test(w) === "legal");
});
return { remainders: filtered, formattedCount: format(filtered.length) };
}, [guesses, showRemaining, word, words]);
};

0 comments on commit 8cc7227

Please sign in to comment.