@scrabble-solver/scrabble-solver 2.10.2 → 2.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +31 -19
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/eslint/.cache_8dgz12 +1 -1
  5. package/.next/cache/next-server.js.nft.json +1 -1
  6. package/.next/cache/webpack/client-production/0.pack +0 -0
  7. package/.next/cache/webpack/client-production/index.pack +0 -0
  8. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  9. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  10. package/.next/cache/webpack/server-production/0.pack +0 -0
  11. package/.next/cache/webpack/server-production/index.pack +0 -0
  12. package/.next/next-server.js.nft.json +1 -1
  13. package/.next/prerender-manifest.json +1 -1
  14. package/.next/routes-manifest.json +1 -1
  15. package/.next/server/chunks/176.js +1269 -1559
  16. package/.next/server/chunks/579.js +50 -26
  17. package/.next/server/middleware-build-manifest.js +1 -1
  18. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  19. package/.next/server/pages/404.html +2 -2
  20. package/.next/server/pages/404.js.nft.json +1 -1
  21. package/.next/server/pages/500.html +2 -2
  22. package/.next/server/pages/_app.js.nft.json +1 -1
  23. package/.next/server/pages/api/dictionary/[locale]/[word].js +2 -1
  24. package/.next/server/pages/api/solve.js +22 -6
  25. package/.next/server/pages/index.html +2 -2
  26. package/.next/server/pages/index.js +1539 -52
  27. package/.next/server/pages/index.js.nft.json +1 -1
  28. package/.next/server/pages/index.json +1 -1
  29. package/.next/server/pages-manifest.json +1 -1
  30. package/.next/static/P7XhuDLmwJJqC8kgPjX42/_buildManifest.js +1 -0
  31. package/.next/static/{FjrbXpI5fkt4lmko-vL_7 → P7XhuDLmwJJqC8kgPjX42}/_ssgManifest.js +0 -0
  32. package/.next/static/chunks/490-d29992f1c264d70e.js +5 -0
  33. package/.next/static/chunks/528-9942ddad0031ff79.js +1 -0
  34. package/.next/static/chunks/pages/{404-24f9617eeb8d6dc1.js → 404-6c99a0c91257c60b.js} +1 -1
  35. package/.next/static/chunks/pages/_app-fa0661b072fc6af9.js +24 -0
  36. package/.next/static/chunks/pages/index-d761f0af070273d2.js +1 -0
  37. package/.next/static/css/78e42ad01f580f64.css +1 -0
  38. package/.next/static/css/97eb6ee0c4300c83.css +1 -0
  39. package/.next/static/css/dcca0c1a39cf5ef5.css +1 -0
  40. package/.next/trace +55 -52
  41. package/package.json +11 -9
  42. package/src/components/Badge/Badge.module.scss +4 -5
  43. package/src/components/Board/BoardPure.tsx +5 -5
  44. package/src/components/Board/components/Cell/Cell.module.scss +15 -2
  45. package/src/components/Button/Button.module.scss +10 -38
  46. package/src/components/Button/Button.tsx +6 -5
  47. package/src/components/Dictionary/Dictionary.module.scss +1 -2
  48. package/src/components/Dictionary/Dictionary.tsx +2 -6
  49. package/src/components/DictionaryInput/DictionaryInput.module.scss +1 -3
  50. package/src/components/EmptyState/EmptyState.module.scss +6 -7
  51. package/src/components/EmptyState/EmptyState.tsx +6 -6
  52. package/src/components/Key/Key.module.scss +0 -1
  53. package/src/components/{Splash/Splash.module.scss → LogoSplashScreen/LogoSplashScreen.module.scss} +1 -1
  54. package/src/components/{Splash/Splash.tsx → LogoSplashScreen/LogoSplashScreen.tsx} +7 -7
  55. package/src/components/LogoSplashScreen/index.ts +1 -0
  56. package/src/components/{Sidebar/Sidebar.module.scss → Modal/Modal.module.scss} +25 -20
  57. package/src/components/{Sidebar/Sidebar.tsx → Modal/Modal.tsx} +9 -9
  58. package/src/components/{Sidebar → Modal}/components/Section/Section.module.scss +0 -0
  59. package/src/components/{Sidebar → Modal}/components/Section/Section.tsx +0 -0
  60. package/src/components/{Sidebar → Modal}/components/Section/index.ts +0 -0
  61. package/src/components/{Sidebar → Modal}/components/index.ts +0 -0
  62. package/src/components/Modal/index.ts +1 -0
  63. package/src/components/NavButtons/NavButtons.tsx +22 -3
  64. package/src/components/Progress/Progress.module.scss +9 -0
  65. package/src/components/Progress/Progress.tsx +38 -0
  66. package/src/components/Progress/index.ts +1 -0
  67. package/src/components/Rack/Rack.module.scss +2 -0
  68. package/src/components/Rack/Rack.tsx +3 -1
  69. package/src/components/Rack/RackTile.tsx +3 -2
  70. package/src/components/ResultCandidatePicker/ResultCandidatePicker.module.scss +76 -0
  71. package/src/components/ResultCandidatePicker/ResultCandidatePicker.tsx +38 -0
  72. package/src/components/ResultCandidatePicker/index.ts +1 -0
  73. package/src/components/Results/Result.tsx +64 -43
  74. package/src/components/Results/Results.module.scss +9 -16
  75. package/src/components/Results/Results.tsx +45 -28
  76. package/src/components/Results/SolveButton.tsx +9 -7
  77. package/src/components/Results/{getColumns.ts → getLocaleColumns.ts} +2 -2
  78. package/src/components/Results/types.ts +16 -0
  79. package/src/components/Results/useColumns.ts +44 -0
  80. package/src/components/ResultsInput/ResultsInput.module.scss +1 -3
  81. package/src/components/Sizer/Sizer.module.scss +10 -0
  82. package/src/components/Sizer/Sizer.tsx +10 -0
  83. package/src/components/Sizer/index.ts +1 -0
  84. package/src/components/Solver/Solver.module.scss +83 -27
  85. package/src/components/Solver/Solver.tsx +157 -24
  86. package/src/components/Solver/components/ApplyButton/ApplyButton.module.scss +5 -0
  87. package/src/components/Solver/components/ApplyButton/ApplyButton.tsx +37 -0
  88. package/src/components/Solver/components/ApplyButton/index.ts +1 -0
  89. package/src/components/Solver/components/EmptyState/EmptyState.module.scss +59 -0
  90. package/src/components/Solver/components/EmptyState/EmptyState.tsx +41 -0
  91. package/src/components/Solver/components/EmptyState/index.ts +1 -0
  92. package/src/components/Solver/components/SolveButton/SolveButton.module.scss +4 -0
  93. package/src/components/Solver/components/SolveButton/SolveButton.tsx +42 -0
  94. package/src/components/Solver/components/SolveButton/index.ts +1 -0
  95. package/src/components/Solver/components/index.ts +3 -0
  96. package/src/components/{Screen/Screen.module.scss → SplashScreen/SplashScreen.module.scss} +2 -12
  97. package/src/components/{Screen/Screen.tsx → SplashScreen/SplashScreen.tsx} +4 -4
  98. package/src/components/SplashScreen/index.ts +1 -0
  99. package/src/components/SquareButton/SquareButton.module.scss +3 -3
  100. package/src/components/Tile/Tile.module.scss +7 -15
  101. package/src/components/Tooltip/Tooltip.module.scss +0 -1
  102. package/src/components/index.ts +6 -7
  103. package/src/hooks/index.ts +1 -1
  104. package/src/hooks/useMediaQuery.ts +11 -0
  105. package/src/hooks/usePortal.tsx +1 -1
  106. package/src/i18n/de.json +2 -0
  107. package/src/i18n/en.json +2 -0
  108. package/src/i18n/es.json +2 -0
  109. package/src/i18n/fa.json +2 -0
  110. package/src/i18n/fr.json +2 -0
  111. package/src/i18n/pl.json +2 -0
  112. package/src/icons/CardChecklist.svg +5 -0
  113. package/src/icons/Check.svg +2 -2
  114. package/src/icons/ChevronDown.svg +4 -0
  115. package/src/icons/CrossCircleFill.svg +4 -0
  116. package/src/icons/{CrossFill.svg → CrossSquareFill.svg} +0 -0
  117. package/src/icons/ExclamationTriangleFill.svg +4 -0
  118. package/src/icons/InfoCircleFill.svg +4 -0
  119. package/src/icons/List.svg +4 -0
  120. package/src/icons/Search.svg +4 -0
  121. package/src/icons/index.ts +8 -2
  122. package/src/{components/KeyMap/KeyMap.tsx → modals/KeyMapModal/KeyMapModal.tsx} +11 -13
  123. package/src/{components/KeyMap → modals/KeyMapModal}/components/Mapping/Mapping.module.scss +0 -0
  124. package/src/{components/KeyMap → modals/KeyMapModal}/components/Mapping/Mapping.tsx +0 -0
  125. package/src/{components/KeyMap → modals/KeyMapModal}/components/Mapping/index.ts +0 -0
  126. package/src/{components/KeyMap → modals/KeyMapModal}/components/index.ts +0 -0
  127. package/src/modals/KeyMapModal/index.ts +1 -0
  128. package/src/{components/KeyMap → modals/KeyMapModal}/keys.tsx +1 -2
  129. package/src/modals/MenuModal/MenuModal.module.scss +46 -0
  130. package/src/modals/MenuModal/MenuModal.tsx +54 -0
  131. package/src/modals/MenuModal/index.ts +1 -0
  132. package/src/modals/RemainingTilesModal/RemainingTilesModal.module.scss +28 -0
  133. package/src/{components/RemainingTiles/RemainingTiles.tsx → modals/RemainingTilesModal/RemainingTilesModal.tsx} +14 -12
  134. package/src/{components/RemainingTiles → modals/RemainingTilesModal/components/Character}/Character.module.scss +6 -2
  135. package/src/{components/RemainingTiles → modals/RemainingTilesModal/components/Character}/Character.tsx +11 -3
  136. package/src/modals/RemainingTilesModal/components/Character/index.ts +1 -0
  137. package/src/modals/RemainingTilesModal/components/index.ts +1 -0
  138. package/src/modals/RemainingTilesModal/index.ts +1 -0
  139. package/src/modals/ResultsModal/ResultsModal.module.scss +7 -0
  140. package/src/modals/ResultsModal/ResultsModal.tsx +58 -0
  141. package/src/modals/ResultsModal/index.ts +1 -0
  142. package/src/modals/SettingsModal/SettingsModal.tsx +34 -0
  143. package/src/{components/Settings → modals/SettingsModal}/components/AutoGroupTilesSetting/AutoGroupTilesSetting.module.scss +0 -0
  144. package/src/{components/Settings → modals/SettingsModal}/components/AutoGroupTilesSetting/AutoGroupTilesSetting.tsx +1 -2
  145. package/src/{components/Settings → modals/SettingsModal}/components/AutoGroupTilesSetting/constants.ts +0 -0
  146. package/src/{components/Settings → modals/SettingsModal}/components/AutoGroupTilesSetting/index.ts +0 -0
  147. package/src/{components/Settings → modals/SettingsModal}/components/AutoGroupTilesSetting/lib.ts +0 -0
  148. package/src/{components/Settings → modals/SettingsModal}/components/ConfigSetting/ConfigSetting.module.scss +0 -0
  149. package/src/{components/Settings → modals/SettingsModal}/components/ConfigSetting/ConfigSetting.tsx +1 -2
  150. package/src/{components/Settings → modals/SettingsModal}/components/ConfigSetting/index.ts +0 -0
  151. package/src/{components/Settings → modals/SettingsModal}/components/ConfigSetting/options.ts +0 -0
  152. package/src/{components/Settings → modals/SettingsModal}/components/ConfigSetting/types.ts +0 -0
  153. package/src/{components/Settings → modals/SettingsModal}/components/LocaleSetting/LocaleSetting.module.scss +0 -0
  154. package/src/{components/Settings → modals/SettingsModal}/components/LocaleSetting/LocaleSetting.tsx +1 -2
  155. package/src/{components/Settings → modals/SettingsModal}/components/LocaleSetting/index.ts +0 -0
  156. package/src/{components/Settings → modals/SettingsModal}/components/LocaleSetting/options.ts +0 -0
  157. package/src/{components/Settings → modals/SettingsModal}/components/LocaleSetting/types.ts +0 -0
  158. package/src/{components/Settings → modals/SettingsModal}/components/index.ts +0 -0
  159. package/src/modals/SettingsModal/index.ts +1 -0
  160. package/src/{components/Words/Words.module.scss → modals/WordsModal/WordsModal.module.scss} +7 -1
  161. package/src/{components/Words/Words.tsx → modals/WordsModal/WordsModal.tsx} +10 -12
  162. package/src/modals/WordsModal/index.ts +1 -0
  163. package/src/modals/index.ts +6 -0
  164. package/src/pages/api/dictionary/[locale]/[word].ts +2 -1
  165. package/src/pages/index.module.scss +6 -4
  166. package/src/pages/index.tsx +63 -26
  167. package/src/parameters/index.ts +28 -6
  168. package/src/state/createAppStore.ts +7 -4
  169. package/src/styles/mixins.scss +15 -13
  170. package/src/styles/variables.scss +15 -17
  171. package/src/types/index.ts +2 -0
  172. package/tsconfig.json +1 -0
  173. package/.next/cache/webpack/client-development/0.pack +0 -0
  174. package/.next/cache/webpack/client-development/1.pack +0 -0
  175. package/.next/cache/webpack/client-development/2.pack +0 -0
  176. package/.next/cache/webpack/client-development/3.pack +0 -0
  177. package/.next/cache/webpack/client-development/4.pack +0 -0
  178. package/.next/cache/webpack/client-development/index.pack +0 -0
  179. package/.next/cache/webpack/client-development/index.pack.old +0 -0
  180. package/.next/cache/webpack/server-development/0.pack +0 -0
  181. package/.next/cache/webpack/server-development/10.pack_ +0 -0
  182. package/.next/cache/webpack/server-development/5.pack_ +0 -0
  183. package/.next/cache/webpack/server-development/8.pack_ +0 -0
  184. package/.next/cache/webpack/server-development/index.pack +0 -0
  185. package/.next/static/FjrbXpI5fkt4lmko-vL_7/_buildManifest.js +0 -1
  186. package/.next/static/chunks/361-d16f336a9752a55a.js +0 -1
  187. package/.next/static/chunks/724-eb48df4d1ba3df8b.js +0 -5
  188. package/.next/static/chunks/amp.js +0 -720
  189. package/.next/static/chunks/main.js +0 -1076
  190. package/.next/static/chunks/pages/_app-959e495f0f221247.js +0 -24
  191. package/.next/static/chunks/pages/_app.js +0 -2121
  192. package/.next/static/chunks/pages/_error.js +0 -28
  193. package/.next/static/chunks/pages/index-1e30dafa41bddb80.js +0 -1
  194. package/.next/static/chunks/pages/index.js +0 -5314
  195. package/.next/static/chunks/react-refresh.js +0 -62
  196. package/.next/static/chunks/webpack.js +0 -1237
  197. package/.next/static/css/aafd07997120f1e4.css +0 -1
  198. package/.next/static/css/c8d26240c04079b9.css +0 -1
  199. package/.next/static/css/eb9d57f7103525ab.css +0 -1
  200. package/.next/static/development/_buildManifest.js +0 -1
  201. package/.next/static/development/_ssgManifest.js +0 -1
  202. package/.next/static/webpack/fb4b50d5e70ee127.webpack.hot-update.json +0 -1
  203. package/.next/static/webpack/pages/index.fb4b50d5e70ee127.hot-update.js +0 -171
  204. package/.next/static/webpack/webpack.fb4b50d5e70ee127.hot-update.js +0 -18
  205. package/src/components/KeyMap/index.ts +0 -1
  206. package/src/components/RemainingTiles/RemainingTiles.module.scss +0 -16
  207. package/src/components/RemainingTiles/index.ts +0 -1
  208. package/src/components/Screen/index.ts +0 -1
  209. package/src/components/Settings/Settings.tsx +0 -35
  210. package/src/components/Settings/index.ts +0 -1
  211. package/src/components/Sidebar/index.ts +0 -1
  212. package/src/components/Splash/index.ts +0 -1
  213. package/src/components/Words/index.ts +0 -1
  214. package/src/hooks/useIsTablet.ts +0 -10
  215. package/src/icons/Play.svg +0 -4
@@ -0,0 +1,44 @@
1
+ import { useMediaQuery } from 'hooks';
2
+ import { LOCALE_FEATURES } from 'i18n';
3
+ import { selectLocale, useTypedSelector } from 'state';
4
+ import { ResultColumn } from 'types';
5
+
6
+ import getLocaleColumns from './getLocaleColumns';
7
+ import { Column } from './types';
8
+
9
+ const COLUMNS_XS = [ResultColumn.Word, ResultColumn.Points];
10
+
11
+ const COLUMNS_S = [...COLUMNS_XS, ResultColumn.BlanksCount, ResultColumn.WordsCount];
12
+
13
+ const COLUMNS_M = [...COLUMNS_XS];
14
+
15
+ const COLUMNS_L = [...COLUMNS_XS];
16
+
17
+ const useColumns = (): Column[] => {
18
+ const locale = useTypedSelector(selectLocale);
19
+ const localeColumns = getLocaleColumns(LOCALE_FEATURES[locale]);
20
+ const isLessThanXs = useMediaQuery('<xs');
21
+ const isLessThanS = useMediaQuery('<s');
22
+ const isLessThanM = useMediaQuery('<m');
23
+ const isLessThanL = useMediaQuery('<l');
24
+
25
+ if (isLessThanXs) {
26
+ return localeColumns.filter((column) => COLUMNS_XS.includes(column.id));
27
+ }
28
+
29
+ if (isLessThanS) {
30
+ return localeColumns.filter((column) => COLUMNS_S.includes(column.id));
31
+ }
32
+
33
+ if (isLessThanM) {
34
+ return localeColumns.filter((column) => COLUMNS_M.includes(column.id));
35
+ }
36
+
37
+ if (isLessThanL) {
38
+ return localeColumns.filter((column) => COLUMNS_L.includes(column.id));
39
+ }
40
+
41
+ return localeColumns;
42
+ };
43
+
44
+ export default useColumns;
@@ -1,9 +1,7 @@
1
1
  @import 'styles/mixins';
2
2
 
3
3
  .resultsInput {
4
- &:focus-within {
5
- @include focus-effect;
6
- }
4
+ @include focus-effect;
7
5
  }
8
6
 
9
7
  .input {
@@ -0,0 +1,10 @@
1
+ .sizer {
2
+ position: absolute;
3
+ top: 0;
4
+ right: 0;
5
+ bottom: 0;
6
+ left: 0;
7
+ width: 100%;
8
+ height: 100%;
9
+ visibility: hidden;
10
+ }
@@ -0,0 +1,10 @@
1
+ import classNames from 'classnames';
2
+ import { forwardRef, HTMLProps } from 'react';
3
+
4
+ import styles from './Sizer.module.scss';
5
+
6
+ const Sizer = forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(({ className, ...props }, ref) => (
7
+ <div className={classNames(styles.sizer, className)} ref={ref} {...props} />
8
+ ));
9
+
10
+ export default Sizer;
@@ -0,0 +1 @@
1
+ export { default } from './Sizer';
@@ -1,46 +1,60 @@
1
1
  @import 'styles/mixins';
2
2
 
3
3
  .solver {
4
+ --spacing: var(--spacing--xl);
5
+
6
+ position: relative;
7
+ margin: 0 var(--spacing);
4
8
  display: flex;
5
9
  flex-direction: column;
6
- height: 100%;
7
- }
8
10
 
9
- .contentWrapper {
10
- $board-size: 15;
11
- $tile-size-max: 60px;
12
- $tile-border-size: 1px;
11
+ @include media('<xl') {
12
+ --spacing: var(--spacing--l);
13
+ }
13
14
 
14
- flex: 1;
15
- padding: 0 var(--spacing--xl);
16
- max-height: $board-size * ($tile-size-max + $tile-border-size) + $tile-border-size;
15
+ @include media('<l', 'touch') {
16
+ margin-bottom: calc(3 * var(--spacing--l) + var(--button--icon--size));
17
+ }
18
+
19
+ @include media('<xs', 'touch') {
20
+ margin-bottom: calc(1 * var(--spacing--m) + 2 * var(--spacing--l) + var(--button--icon--size));
21
+ }
17
22
  }
18
23
 
19
- .content {
24
+ .container {
25
+ position: relative;
20
26
  display: flex;
21
27
  align-items: center;
22
28
  justify-content: center;
23
- height: 100%;
24
- gap: var(--spacing--xl);
29
+ }
25
30
 
26
- @include tablet {
27
- gap: var(--spacing--l);
31
+ .content {
32
+ display: grid;
33
+ grid-template-columns: minmax(0, 1fr) var(--solver-column--width);
34
+ gap: var(--spacing);
35
+ margin: 0 auto;
36
+
37
+ @include media('<l') {
38
+ grid-template-columns: 1fr;
28
39
  }
29
40
  }
30
41
 
31
42
  .boardContainer {
32
- display: flex;
33
43
  position: relative;
34
44
  }
35
45
 
36
- .sidebar {
46
+ .board {
47
+ margin: 0 auto;
48
+ }
49
+
50
+ .column {
37
51
  display: flex;
38
52
  flex-direction: column;
39
- flex: 0 0 var(--sidebar--width);
40
- gap: var(--spacing--xl);
53
+ flex: 0 0 var(--solver-column--width);
54
+ gap: var(--spacing);
41
55
 
42
- @include tablet {
43
- gap: var(--spacing--l);
56
+ @include media('<l') {
57
+ display: none;
44
58
  }
45
59
  }
46
60
 
@@ -63,17 +77,24 @@
63
77
  position: relative;
64
78
  }
65
79
 
66
- .rackContainer {
67
- position: relative;
68
- z-index: 1;
80
+ .bottomContainer {
69
81
  flex: 0 0 auto;
70
82
  display: flex;
71
83
  justify-content: center;
72
- margin: var(--spacing--xl) var(--spacing--l);
84
+ }
73
85
 
74
- @include tablet {
75
- margin: var(--spacing--l);
76
- }
86
+ .bottomContent {
87
+ display: inline-flex;
88
+ flex-direction: column;
89
+ align-items: center;
90
+ gap: var(--spacing);
91
+ margin: var(--spacing) auto;
92
+ min-width: 0;
93
+ }
94
+
95
+ .rackContainer {
96
+ display: flex;
97
+ justify-content: center;
77
98
  }
78
99
 
79
100
  .rack {
@@ -83,3 +104,38 @@
83
104
  .submitInput {
84
105
  display: none;
85
106
  }
107
+
108
+ .controls {
109
+ width: 100%;
110
+ display: flex;
111
+ align-items: flex-start;
112
+ justify-content: center;
113
+ gap: var(--spacing--l);
114
+ }
115
+
116
+ .resultCandidatePicker {
117
+ flex: 1;
118
+ }
119
+
120
+ .apply {
121
+ flex: 0 0 auto;
122
+ }
123
+
124
+ .solve {
125
+ --spacing: var(--spacing--l);
126
+
127
+ position: fixed;
128
+ bottom: var(--spacing);
129
+
130
+ @include media('<xs') {
131
+ --spacing: var(--spacing--m);
132
+ }
133
+
134
+ [dir='ltr'] & {
135
+ right: var(--spacing);
136
+ }
137
+
138
+ [dir='rtl'] & {
139
+ left: var(--spacing);
140
+ }
141
+ }
@@ -1,56 +1,139 @@
1
+ import { Result } from '@scrabble-solver/types';
1
2
  import classNames from 'classnames';
2
- import { FormEvent, FunctionComponent } from 'react';
3
+ import { FormEvent, FunctionComponent, useEffect, useMemo } from 'react';
3
4
  import { useDispatch } from 'react-redux';
4
5
  import { useMeasure } from 'react-use';
5
6
 
6
- import { useIsTablet } from 'hooks';
7
- import { getCellSize } from 'lib';
8
- import { COMPONENTS_SPACING, COMPONENTS_SPACING_MOBILE, DICTIONARY_HEIGHT } from 'parameters';
9
- import { selectConfig, solveSlice, useTypedSelector } from 'state';
7
+ import { useIsTouchDevice, useMediaQuery } from 'hooks';
8
+ import {
9
+ BOARD_TILE_SIZE_MAX,
10
+ BOARD_TILE_SIZE_MIN,
11
+ BORDER_WIDTH,
12
+ COLUMN_MIN_HEIGHT,
13
+ COMPONENTS_SPACING,
14
+ COMPONENTS_SPACING_SMALL,
15
+ DICTIONARY_HEIGHT,
16
+ RACK_TILE_SIZE_MAX,
17
+ } from 'parameters';
18
+ import {
19
+ resultsSlice,
20
+ selectAreResultsOutdated,
21
+ selectConfig,
22
+ selectResultCandidate,
23
+ selectSolveError,
24
+ selectSortedFilteredResults,
25
+ selectSortedResults,
26
+ solveSlice,
27
+ useTranslate,
28
+ useTypedSelector,
29
+ } from 'state';
10
30
 
11
31
  import Board from '../Board';
12
32
  import Dictionary from '../Dictionary';
13
33
  import DictionaryInput from '../DictionaryInput';
14
34
  import Rack from '../Rack';
35
+ import ResultCandidatePicker from '../ResultCandidatePicker';
15
36
  import Results from '../Results';
16
37
  import Well from '../Well';
17
38
 
39
+ import { ApplyButton, EmptyState, SolveButton } from './components';
18
40
  import styles from './Solver.module.scss';
19
41
 
20
42
  interface Props {
21
43
  className?: string;
44
+ height: number;
45
+ width: number;
46
+ onShowResults: () => void;
22
47
  }
23
48
 
24
- const Solver: FunctionComponent<Props> = ({ className }) => {
49
+ // eslint-disable-next-line max-statements
50
+ const Solver: FunctionComponent<Props> = ({ className, height, width, onShowResults }) => {
25
51
  const dispatch = useDispatch();
26
- const isTablet = useIsTablet();
27
- const [boardRef, { height: boardHeight }] = useMeasure<HTMLDivElement>();
28
- const [contentRef, { height: contentHeight, width: contentWidth }] = useMeasure<HTMLDivElement>();
29
- const [resultsContainerRef, { height: resultsContainerHeight, width: resultsContainerWidth }] =
30
- useMeasure<HTMLDivElement>();
52
+ const translate = useTranslate();
53
+ const isTouchDevice = useIsTouchDevice();
54
+ const [bottomContainerRef, { height: bottomContainerHeight }] = useMeasure<HTMLDivElement>();
55
+ const [resultsContainerRef, { width: resultsContainerWidth }] = useMeasure<HTMLDivElement>();
56
+ const isLessThanXl = useMediaQuery('<xl');
57
+ const isLessThanL = useMediaQuery('<l');
58
+ const componentsSpacing = isLessThanXl ? COMPONENTS_SPACING_SMALL : COMPONENTS_SPACING;
59
+ const maxBoardWidth = width - resultsContainerWidth - (isLessThanL ? 0 : componentsSpacing) - 2 * componentsSpacing;
60
+ const maxBoardHeight = Math.max(height - bottomContainerHeight, isLessThanL ? 0 : COLUMN_MIN_HEIGHT);
31
61
  const config = useTypedSelector(selectConfig);
32
- const cellSize = getCellSize(config, contentWidth - resultsContainerWidth, contentHeight);
33
- const componentsSpacing = isTablet ? COMPONENTS_SPACING_MOBILE : COMPONENTS_SPACING;
34
- const resultsHeight = boardHeight - DICTIONARY_HEIGHT - componentsSpacing;
62
+ const resultCandidate = useTypedSelector(selectResultCandidate);
63
+ const isOutdated = useTypedSelector(selectAreResultsOutdated);
64
+ const allResults = useTypedSelector(selectSortedResults);
65
+ const error = useTypedSelector(selectSolveError);
66
+ const results = useTypedSelector(selectSortedFilteredResults);
67
+ const [bestResult] = results || [];
68
+ const cellWidth = (maxBoardWidth - (config.boardWidth + 1) * BORDER_WIDTH) / config.boardWidth;
69
+ const cellHeight = (maxBoardHeight - (config.boardHeight + 1) * BORDER_WIDTH) / config.boardHeight;
70
+ const cellSize = Math.min(cellWidth, cellHeight);
71
+ const cellSizeSafe = Math.min(Math.max(cellSize, BOARD_TILE_SIZE_MIN), BOARD_TILE_SIZE_MAX);
72
+ const tileSize = Math.min((maxBoardWidth - 2 * BORDER_WIDTH) / config.maximumCharactersCount, RACK_TILE_SIZE_MAX);
73
+ const boardSize = (cellSizeSafe + BORDER_WIDTH) * Math.max(config.boardWidth, config.boardHeight) + BORDER_WIDTH;
74
+ const resultsHeight = boardSize - DICTIONARY_HEIGHT - componentsSpacing - 4 * BORDER_WIDTH;
75
+ const maxControlsWidth = tileSize * config.maximumCharactersCount + 2 * BORDER_WIDTH;
76
+ const touchCallbacks = useMemo(
77
+ () => ({
78
+ onClick: (result: Result) => {
79
+ const isSelected = result === resultCandidate;
80
+
81
+ if (isSelected) {
82
+ dispatch(resultsSlice.actions.applyResult(result));
83
+ } else {
84
+ dispatch(resultsSlice.actions.changeResultCandidate(result));
85
+ }
86
+ },
87
+ }),
88
+ [dispatch, resultCandidate],
89
+ );
90
+ const mouseCallbacks = useMemo(
91
+ () => ({
92
+ onBlur: () => {
93
+ dispatch(resultsSlice.actions.changeResultCandidate(null));
94
+ },
95
+ onClick: (result: Result) => {
96
+ dispatch(resultsSlice.actions.applyResult(result));
97
+ },
98
+ onFocus: (result: Result) => {
99
+ dispatch(resultsSlice.actions.changeResultCandidate(result));
100
+ },
101
+ onMouseEnter: (result: Result) => {
102
+ dispatch(resultsSlice.actions.changeResultCandidate(result));
103
+ },
104
+ onMouseLeave: () => {
105
+ dispatch(resultsSlice.actions.changeResultCandidate(null));
106
+ },
107
+ }),
108
+ [dispatch],
109
+ );
110
+ const callbacks = isTouchDevice ? touchCallbacks : mouseCallbacks;
35
111
 
36
112
  const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
37
113
  event.preventDefault();
114
+ onShowResults();
38
115
  dispatch(solveSlice.actions.submit());
39
116
  };
40
117
 
118
+ useEffect(() => {
119
+ if (bestResult) {
120
+ dispatch(resultsSlice.actions.changeResultCandidate(bestResult));
121
+ }
122
+ }, [bestResult, dispatch]);
123
+
41
124
  return (
42
125
  <div className={classNames(styles.solver, className)}>
43
- <div className={styles.contentWrapper}>
44
- <div className={styles.content} ref={contentRef}>
126
+ <div className={styles.container}>
127
+ <div className={styles.content}>
45
128
  <form className={styles.boardContainer} onSubmit={handleSubmit}>
46
- {contentWidth > 0 && <Board cellSize={cellSize} innerRef={boardRef} />}
129
+ <Board cellSize={cellSizeSafe} className={styles.board} />
47
130
  <input className={styles.submitInput} tabIndex={-1} type="submit" />
48
131
  </form>
49
132
 
50
- <div className={styles.sidebar} style={{ height: boardHeight + 1 }}>
133
+ <div className={styles.column}>
51
134
  <Well className={styles.resultsContainer} ref={resultsContainerRef}>
52
- {resultsContainerWidth > 0 && resultsContainerHeight > 0 && (
53
- <Results height={resultsHeight} width={resultsContainerWidth} />
135
+ {resultsContainerWidth > 0 && resultsHeight > 0 && (
136
+ <Results callbacks={callbacks} height={resultsHeight} width={resultsContainerWidth} />
54
137
  )}
55
138
  </Well>
56
139
 
@@ -64,10 +147,60 @@ const Solver: FunctionComponent<Props> = ({ className }) => {
64
147
  </div>
65
148
  </div>
66
149
 
67
- <form className={styles.rackContainer} onSubmit={handleSubmit}>
68
- <Rack className={styles.rack} />
69
- <input className={styles.submitInput} tabIndex={-1} type="submit" />
70
- </form>
150
+ <div className={styles.bottomContainer} ref={bottomContainerRef}>
151
+ <div className={styles.bottomContent}>
152
+ <form className={styles.rackContainer} onSubmit={handleSubmit}>
153
+ <Rack className={styles.rack} tileSize={tileSize} />
154
+ <input className={styles.submitInput} tabIndex={-1} type="submit" />
155
+ </form>
156
+
157
+ {isLessThanL && (
158
+ <div className={styles.controls} style={{ maxWidth: maxControlsWidth }}>
159
+ {typeof error !== 'undefined' && (
160
+ <EmptyState variant="error" onClick={onShowResults}>
161
+ {error.message}
162
+ </EmptyState>
163
+ )}
164
+
165
+ {typeof error === 'undefined' && typeof results === 'undefined' && (
166
+ <EmptyState variant="info" onClick={onShowResults}>
167
+ {translate('results.empty-state.uninitialized')}
168
+ </EmptyState>
169
+ )}
170
+
171
+ {typeof error === 'undefined' && typeof results !== 'undefined' && typeof allResults !== 'undefined' && (
172
+ <>
173
+ {isOutdated && (
174
+ <EmptyState variant="info" onClick={onShowResults}>
175
+ {translate('results.empty-state.outdated')}
176
+ </EmptyState>
177
+ )}
178
+
179
+ {!isOutdated && (
180
+ <>
181
+ {allResults.length === 0 && (
182
+ <EmptyState variant="warning" onClick={onShowResults}>
183
+ {translate('results.empty-state.no-results')}
184
+ </EmptyState>
185
+ )}
186
+
187
+ {allResults.length > 0 && resultCandidate && (
188
+ <ResultCandidatePicker className={styles.resultCandidatePicker} onClick={onShowResults} />
189
+ )}
190
+ </>
191
+ )}
192
+ </>
193
+ )}
194
+
195
+ {allResults && allResults.length > 0 && !isOutdated && (
196
+ <ApplyButton className={classNames(styles.submit, styles.apply)} />
197
+ )}
198
+ </div>
199
+ )}
200
+ </div>
201
+ </div>
202
+
203
+ {isTouchDevice && <SolveButton className={styles.solve} onClick={onShowResults} />}
71
204
  </div>
72
205
  );
73
206
  };
@@ -0,0 +1,5 @@
1
+ @import 'styles/mixins';
2
+
3
+ .icon {
4
+ transform: scale(1.5);
5
+ }
@@ -0,0 +1,37 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { useDispatch } from 'react-redux';
3
+
4
+ import { Check } from 'icons';
5
+ import { resultsSlice, selectResultCandidate, useTypedSelector } from 'state';
6
+
7
+ import Button from '../../../Button';
8
+
9
+ import styles from './ApplyButton.module.scss';
10
+
11
+ interface Props {
12
+ className?: string;
13
+ }
14
+
15
+ const ApplyButton: FunctionComponent<Props> = ({ className }) => {
16
+ const dispatch = useDispatch();
17
+ const resultCandidate = useTypedSelector(selectResultCandidate);
18
+
19
+ const handleClick = () => {
20
+ if (resultCandidate) {
21
+ dispatch(resultsSlice.actions.applyResult(resultCandidate));
22
+ }
23
+ };
24
+
25
+ return (
26
+ <Button
27
+ className={className}
28
+ disabled={!resultCandidate}
29
+ Icon={Check}
30
+ iconClassName={styles.icon}
31
+ type="submit"
32
+ onClick={handleClick}
33
+ />
34
+ );
35
+ };
36
+
37
+ export default ApplyButton;
@@ -0,0 +1 @@
1
+ export { default } from './ApplyButton';
@@ -0,0 +1,59 @@
1
+ .emptyState {
2
+ display: flex;
3
+ min-width: 0;
4
+ width: 100%;
5
+ border: var(--border);
6
+ border-radius: var(--border--radius);
7
+ background-color: white;
8
+ box-shadow: var(--box-shadow);
9
+ cursor: pointer;
10
+ text-align: center;
11
+ }
12
+
13
+ .iconContainer {
14
+ flex: 0 0 auto;
15
+ display: flex;
16
+ align-items: center;
17
+ justify-content: center;
18
+ padding: var(--spacing--m);
19
+ color: var(--color--foreground--secondary);
20
+
21
+ [dir='ltr'] & {
22
+ border-top-left-radius: var(--border--radius);
23
+ border-bottom-left-radius: var(--border--radius);
24
+ border-right: var(--border);
25
+ }
26
+
27
+ [dir='rtl'] & {
28
+ border-top-right-radius: var(--border--radius);
29
+ border-bottom-right-radius: var(--border--radius);
30
+ border-left: var(--border);
31
+ }
32
+
33
+ .error & {
34
+ background-color: var(--color--red--light);
35
+ color: var(--color--error);
36
+ }
37
+
38
+ .warning & {
39
+ background-color: var(--color--yellow--light);
40
+ color: var(--color--warning);
41
+ }
42
+
43
+ .info & {
44
+ background-color: var(--color--blue--light);
45
+ color: var(--color--info);
46
+ }
47
+ }
48
+
49
+ .icon {
50
+ $size: 24px;
51
+
52
+ width: $size;
53
+ height: $size;
54
+ }
55
+
56
+ .content {
57
+ flex: 1;
58
+ padding: var(--spacing--m) var(--spacing--l);
59
+ }
@@ -0,0 +1,41 @@
1
+ import classNames from 'classnames';
2
+ import { FunctionComponent, HTMLProps, ReactNode, SVGAttributes } from 'react';
3
+
4
+ import { CrossCircleFill, ExclamationTriangleFill, InfoCircleFill } from 'icons';
5
+
6
+ import styles from './EmptyState.module.scss';
7
+
8
+ interface Props extends HTMLProps<HTMLDivElement> {
9
+ children: ReactNode;
10
+ className?: string;
11
+ variant: 'error' | 'info' | 'warning';
12
+ }
13
+
14
+ const ICON_PER_TYPE: Record<Props['variant'], FunctionComponent<SVGAttributes<SVGElement>>> = {
15
+ error: CrossCircleFill,
16
+ info: InfoCircleFill,
17
+ warning: ExclamationTriangleFill,
18
+ };
19
+
20
+ const EmptyState: FunctionComponent<Props> = ({ children, className, variant, ...props }) => {
21
+ const Icon = ICON_PER_TYPE[variant];
22
+
23
+ return (
24
+ <div
25
+ className={classNames(styles.emptyState, className, {
26
+ [styles.error]: variant === 'error',
27
+ [styles.info]: variant === 'info',
28
+ [styles.warning]: variant === 'warning',
29
+ })}
30
+ {...props}
31
+ >
32
+ <div className={styles.iconContainer}>
33
+ <Icon className={styles.icon} />
34
+ </div>
35
+
36
+ <div className={styles.content}>{children}</div>
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export default EmptyState;
@@ -0,0 +1 @@
1
+ export { default } from './EmptyState';
@@ -0,0 +1,4 @@
1
+ .solveButton {
2
+ padding: var(--spacing--l);
3
+ border-radius: 50%;
4
+ }
@@ -0,0 +1,42 @@
1
+ import classNames from 'classnames';
2
+ import { FunctionComponent, MouseEventHandler } from 'react';
3
+ import { useDispatch } from 'react-redux';
4
+
5
+ import { Search } from 'icons';
6
+ import { noop } from 'lib';
7
+ import { selectAreResultsOutdated, selectIsLoading, selectRack, solveSlice, useTypedSelector } from 'state';
8
+
9
+ import Button from '../../../Button';
10
+
11
+ import styles from './SolveButton.module.scss';
12
+
13
+ interface Props {
14
+ className?: string;
15
+ onClick?: MouseEventHandler;
16
+ }
17
+
18
+ const SolveButton: FunctionComponent<Props> = ({ className, onClick = noop }) => {
19
+ const dispatch = useDispatch();
20
+ const isLoading = useTypedSelector(selectIsLoading);
21
+ const isOutdated = useTypedSelector(selectAreResultsOutdated);
22
+ const rack = useTypedSelector(selectRack);
23
+ const hasTiles = rack.some((tile) => tile !== null);
24
+
25
+ const handleClick: MouseEventHandler = (event) => {
26
+ dispatch(solveSlice.actions.submit());
27
+ onClick(event);
28
+ };
29
+
30
+ return (
31
+ <Button
32
+ className={classNames(styles.solveButton, className)}
33
+ disabled={isLoading || !isOutdated || !hasTiles}
34
+ Icon={Search}
35
+ iconClassName={styles.icon}
36
+ type="submit"
37
+ onClick={handleClick}
38
+ />
39
+ );
40
+ };
41
+
42
+ export default SolveButton;
@@ -0,0 +1 @@
1
+ export { default } from './SolveButton';
@@ -0,0 +1,3 @@
1
+ export { default as ApplyButton } from './ApplyButton';
2
+ export { default as EmptyState } from './EmptyState';
3
+ export { default as SolveButton } from './SolveButton';