@terrafirmagreg-team/recipe 0.0.0-stage → 1.2.0

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 (221) hide show
  1. package/package.json +62 -3
  2. package/src/components/button-copy.tsx +43 -0
  3. package/src/components/cards/card/index.tsx +214 -0
  4. package/src/components/cards/card/scene.tsx +107 -0
  5. package/src/components/cards/card/strip.tsx +198 -0
  6. package/src/components/cards/card/text.tsx +46 -0
  7. package/src/components/cards/card/tips.tsx +63 -0
  8. package/src/components/cards/default-item.tsx +47 -0
  9. package/src/components/cards/glare-filter.tsx +29 -0
  10. package/src/components/cards/paged-card.tsx +222 -0
  11. package/src/components/cards/slot-hitbox.tsx +213 -0
  12. package/src/components/cards/strip-card/buttons.tsx +106 -0
  13. package/src/components/cards/strip-card/index.tsx +214 -0
  14. package/src/components/cards/strip-card/member-cell.tsx +167 -0
  15. package/src/components/cards/strip-card/sprite.tsx +36 -0
  16. package/src/components/embed-card.tsx +44 -0
  17. package/src/components/mdx/recipe.tsx +129 -0
  18. package/src/components/tool-list.tsx +49 -0
  19. package/src/components/tree.tsx +98 -0
  20. package/src/components/views/alloy/index.tsx +112 -0
  21. package/src/components/views/alloy/list.tsx +85 -0
  22. package/src/components/views/alloy/mix/index.tsx +35 -0
  23. package/src/components/views/alloy/mix/ratio.tsx +94 -0
  24. package/src/components/views/alloy/mix/rows.tsx +145 -0
  25. package/src/components/views/alloy/mix/status.tsx +122 -0
  26. package/src/components/views/alloy/mix/total.tsx +132 -0
  27. package/src/components/views/alloy/range-bar.tsx +65 -0
  28. package/src/components/views/alloy/stack-bar.tsx +88 -0
  29. package/src/components/views/browser/axis-switcher.tsx +54 -0
  30. package/src/components/views/browser/card-grid.tsx +275 -0
  31. package/src/components/views/browser/favorite-button.tsx +46 -0
  32. package/src/components/views/browser/frame.tsx +112 -0
  33. package/src/components/views/browser/index.tsx +114 -0
  34. package/src/components/views/browser/item-panel/index.tsx +229 -0
  35. package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
  36. package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
  37. package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
  38. package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
  39. package/src/components/views/browser/item-view/index.tsx +186 -0
  40. package/src/components/views/browser/item-view/tags.tsx +85 -0
  41. package/src/components/views/browser/item-view-header.tsx +131 -0
  42. package/src/components/views/browser/pane-tabs.tsx +61 -0
  43. package/src/components/views/browser/place-header.tsx +72 -0
  44. package/src/components/views/browser/query-controls.tsx +105 -0
  45. package/src/components/views/browser/recipe-item-header.tsx +60 -0
  46. package/src/components/views/browser/settings.tsx +52 -0
  47. package/src/components/views/browser/toolbar.tsx +54 -0
  48. package/src/components/views/browser/type-tabs.tsx +71 -0
  49. package/src/components/views/browser/type-view.tsx +184 -0
  50. package/src/components/views/browser/workstation-rail.tsx +43 -0
  51. package/src/components/views/calc/calculator/actions.tsx +47 -0
  52. package/src/components/views/calc/calculator/help.tsx +189 -0
  53. package/src/components/views/calc/calculator/index.tsx +172 -0
  54. package/src/components/views/calc/dot-overlay.tsx +80 -0
  55. package/src/components/views/calc/edge.tsx +152 -0
  56. package/src/components/views/calc/flow/index.tsx +305 -0
  57. package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
  58. package/src/components/views/calc/flow/toolbar.tsx +60 -0
  59. package/src/components/views/calc/flow/view-menu.tsx +117 -0
  60. package/src/components/views/calc/member-picker.tsx +120 -0
  61. package/src/components/views/calc/node-card/actions.tsx +90 -0
  62. package/src/components/views/calc/node-card/badges.tsx +59 -0
  63. package/src/components/views/calc/node-card/chips.tsx +187 -0
  64. package/src/components/views/calc/node-card/far.tsx +123 -0
  65. package/src/components/views/calc/node-card/full.tsx +332 -0
  66. package/src/components/views/calc/node-card/index.tsx +27 -0
  67. package/src/components/views/calc/node-card/menu.tsx +282 -0
  68. package/src/components/views/calc/node-card/port-cells.tsx +186 -0
  69. package/src/components/views/calc/node-card/port-rails.tsx +251 -0
  70. package/src/components/views/calc/node-card/ports.tsx +86 -0
  71. package/src/components/views/calc/recipe-picker/body.tsx +207 -0
  72. package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
  73. package/src/components/views/calc/recipe-picker/index.tsx +52 -0
  74. package/src/components/views/calc/sidebar.tsx +171 -0
  75. package/src/components/views/calc/trees/icon-picker.tsx +97 -0
  76. package/src/components/views/calc/trees/index.tsx +134 -0
  77. package/src/components/views/calc/trees/label.tsx +67 -0
  78. package/src/components/views/calc/trees/rows.tsx +140 -0
  79. package/src/components/views/forge/gui.tsx +131 -0
  80. package/src/components/views/forge/index.tsx +112 -0
  81. package/src/components/views/forge/list.tsx +113 -0
  82. package/src/components/views/forge/workbench/controls.tsx +103 -0
  83. package/src/components/views/forge/workbench/index.tsx +85 -0
  84. package/src/components/views/forge/workbench/panel.tsx +228 -0
  85. package/src/components/views/forge/workbench/ruler.tsx +133 -0
  86. package/src/components/views/forge/workbench/status.tsx +55 -0
  87. package/src/components/views/forge/workbench/tape.tsx +70 -0
  88. package/src/hooks/alloy/use-fluid-colors.ts +125 -0
  89. package/src/hooks/alloy/use-mix-state.ts +240 -0
  90. package/src/hooks/calc/flow/use-engage.ts +129 -0
  91. package/src/hooks/calc/flow/use-handlers.ts +192 -0
  92. package/src/hooks/calc/flow/use-layout.ts +105 -0
  93. package/src/hooks/calc/flow/use-mount.ts +97 -0
  94. package/src/hooks/calc/flow/use-nodes.ts +260 -0
  95. package/src/hooks/calc/flow/use-pickers.ts +57 -0
  96. package/src/hooks/calc/flow/use-viewport.ts +141 -0
  97. package/src/hooks/calc/flow/use-window.ts +87 -0
  98. package/src/hooks/calc/use-actions.ts +355 -0
  99. package/src/hooks/calc/use-amounts.ts +64 -0
  100. package/src/hooks/calc/use-data.ts +203 -0
  101. package/src/hooks/calc/use-defaults.ts +40 -0
  102. package/src/hooks/calc/use-far-mode.ts +37 -0
  103. package/src/hooks/calc/use-focus.ts +31 -0
  104. package/src/hooks/calc/use-maps.ts +76 -0
  105. package/src/hooks/calc/use-reset.ts +15 -0
  106. package/src/hooks/calc/use-resolver.ts +70 -0
  107. package/src/hooks/calc/use-session.ts +13 -0
  108. package/src/hooks/calc/use-share.ts +64 -0
  109. package/src/hooks/calc/use-storage.ts +126 -0
  110. package/src/hooks/calc/use-tier.ts +13 -0
  111. package/src/hooks/calc/use-view-mode.ts +24 -0
  112. package/src/hooks/calc/use-worker.ts +204 -0
  113. package/src/hooks/forge/use-anvil-gui.ts +16 -0
  114. package/src/hooks/forge/use-forge-state.ts +135 -0
  115. package/src/hooks/forge/use-ruler.ts +100 -0
  116. package/src/hooks/use-add-to-calc.ts +51 -0
  117. package/src/hooks/use-categories-by-id.ts +18 -0
  118. package/src/hooks/use-favorite-hotkey.ts +39 -0
  119. package/src/hooks/use-favorites.ts +135 -0
  120. package/src/hooks/use-group-outlines.ts +65 -0
  121. package/src/hooks/use-hide-unused.ts +12 -0
  122. package/src/hooks/use-index.ts +72 -0
  123. package/src/hooks/use-item-feeds.ts +46 -0
  124. package/src/hooks/use-item-pane.ts +106 -0
  125. package/src/hooks/use-item-press.ts +89 -0
  126. package/src/hooks/use-item-tag-groups.ts +54 -0
  127. package/src/hooks/use-item-tooltips.ts +18 -0
  128. package/src/hooks/use-left-sidebar-tree.ts +34 -0
  129. package/src/hooks/use-mod-names.ts +17 -0
  130. package/src/hooks/use-mount-limit.ts +22 -0
  131. package/src/hooks/use-panel-cells.ts +117 -0
  132. package/src/hooks/use-panel-page.ts +54 -0
  133. package/src/hooks/use-panel-tabs.ts +43 -0
  134. package/src/hooks/use-query.ts +186 -0
  135. package/src/hooks/use-session.ts +88 -0
  136. package/src/hooks/use-sidebar-group.ts +16 -0
  137. package/src/hooks/use-tag-members.ts +16 -0
  138. package/src/hooks/use-tool-recipes.ts +26 -0
  139. package/src/hooks/use-type-filter.ts +73 -0
  140. package/src/lib/alloy/mix.ts +210 -0
  141. package/src/lib/alloy/parse.ts +37 -0
  142. package/src/lib/calc/defaults.ts +47 -0
  143. package/src/lib/calc/flow.ts +315 -0
  144. package/src/lib/calc/focus.ts +15 -0
  145. package/src/lib/calc/meta.ts +17 -0
  146. package/src/lib/calc/pack.ts +77 -0
  147. package/src/lib/calc/ports.ts +43 -0
  148. package/src/lib/calc/resolve.ts +198 -0
  149. package/src/lib/calc/route/buckets.ts +49 -0
  150. package/src/lib/calc/route/geometry.ts +51 -0
  151. package/src/lib/calc/route/index.ts +3 -0
  152. package/src/lib/calc/route/polyline.ts +103 -0
  153. package/src/lib/calc/route/router.ts +394 -0
  154. package/src/lib/calc/scheme.ts +226 -0
  155. package/src/lib/calc/storage/entry.ts +97 -0
  156. package/src/lib/calc/storage/index.ts +20 -0
  157. package/src/lib/calc/storage/keys.ts +38 -0
  158. package/src/lib/calc/storage/store.ts +198 -0
  159. package/src/lib/calc/tree/index.ts +4 -0
  160. package/src/lib/calc/tree/materials.ts +29 -0
  161. package/src/lib/calc/tree/recipe.ts +104 -0
  162. package/src/lib/calc/tree/share.ts +135 -0
  163. package/src/lib/calc/worker/api.ts +25 -0
  164. package/src/lib/calc/worker/fetch.ts +66 -0
  165. package/src/lib/calc/worker/flush.ts +39 -0
  166. package/src/lib/calc/worker/index.ts +8 -0
  167. package/src/lib/calc/worker/protocol.ts +35 -0
  168. package/src/lib/calc/worker/resolve.ts +49 -0
  169. package/src/lib/calc/worker/state.ts +48 -0
  170. package/src/lib/card-model.ts +65 -0
  171. package/src/lib/client/recipe-categories.ts +14 -0
  172. package/src/lib/client/recipe.ts +85 -0
  173. package/src/lib/client-index/catalog.ts +91 -0
  174. package/src/lib/client-index/chrome.ts +180 -0
  175. package/src/lib/client-index/index.ts +20 -0
  176. package/src/lib/client-index/registry.ts +121 -0
  177. package/src/lib/client-index/rows.ts +260 -0
  178. package/src/lib/client-index/tooltips.ts +74 -0
  179. package/src/lib/config.ts +18 -0
  180. package/src/lib/data/category/dto.ts +25 -0
  181. package/src/lib/data/category/load.ts +47 -0
  182. package/src/lib/data/category/parse.ts +71 -0
  183. package/src/lib/data/dto.ts +152 -0
  184. package/src/lib/data/grid.ts +40 -0
  185. package/src/lib/data/parse/entry.ts +85 -0
  186. package/src/lib/data/parse/index.ts +3 -0
  187. package/src/lib/data/parse/layout.ts +138 -0
  188. package/src/lib/data/parse/slots.ts +85 -0
  189. package/src/lib/data/parse/widgets.ts +81 -0
  190. package/src/lib/data/scene.ts +103 -0
  191. package/src/lib/data/slot-io.ts +44 -0
  192. package/src/lib/dump.ts +6 -0
  193. package/src/lib/embed.ts +22 -0
  194. package/src/lib/favorite-hover.ts +13 -0
  195. package/src/lib/fluid-outputs.ts +70 -0
  196. package/src/lib/forge/actions.ts +59 -0
  197. package/src/lib/forge/data.ts +51 -0
  198. package/src/lib/forge/solve.ts +80 -0
  199. package/src/lib/group.ts +23 -0
  200. package/src/lib/index-store.ts +70 -0
  201. package/src/lib/links.ts +131 -0
  202. package/src/lib/lookup.ts +119 -0
  203. package/src/lib/panel-outline.ts +86 -0
  204. package/src/lib/panel.ts +105 -0
  205. package/src/lib/preview.ts +32 -0
  206. package/src/lib/recipe-slots.ts +8 -0
  207. package/src/lib/search.ts +139 -0
  208. package/src/lib/sidebar.ts +47 -0
  209. package/src/lib/used-items.ts +25 -0
  210. package/src/locales/en_us.json +172 -0
  211. package/src/locales/ru_ru.json +172 -0
  212. package/src/locales.ts +6 -0
  213. package/src/types/alloy.ts +20 -0
  214. package/src/types/calc-flow-props.ts +44 -0
  215. package/src/types/calc.ts +92 -0
  216. package/src/types/forge.ts +21 -0
  217. package/src/types/index.ts +136 -0
  218. package/styles/calc.css +308 -0
  219. package/styles/strip.css +7 -0
  220. package/styles.css +2 -0
  221. package/README.md +0 -3
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { useCallback } from 'react';
5
+ import {
6
+ createStoredValue,
7
+ type StoredCodec,
8
+ } from '@terrafirmagreg-team/ui/lib/utils/stored-value';
9
+
10
+ const codec: StoredCodec<Record<string, number>> = {
11
+ read: (raw) => {
12
+ if (!raw) return {};
13
+ try {
14
+ const parsed: unknown = JSON.parse(raw);
15
+ if (!parsed || typeof parsed !== 'object') return {};
16
+ const out: Record<string, number> = {};
17
+ for (const [key, value] of Object.entries(
18
+ parsed as Record<string, unknown>,
19
+ )) {
20
+ const page = Math.floor(Number(value));
21
+ if (Number.isFinite(page) && page > 0) out[key] = page;
22
+ }
23
+ return out;
24
+ } catch {
25
+ return {};
26
+ }
27
+ },
28
+ write: (value) => JSON.stringify(value),
29
+ };
30
+
31
+ const useStoredPanelPages = createStoredValue(
32
+ 'wiki.recipe.panelPage',
33
+ codec,
34
+ );
35
+
36
+ export function usePanelPage(dataset: DatasetRef) {
37
+ const [pages, setPages] = useStoredPanelPages();
38
+ const refKey = `${dataset.id}/${dataset.version ?? ''}`;
39
+ const setPage = useCallback(
40
+ (page: number) => {
41
+ setPages((prev) => {
42
+ const next = page > 0 ? page : 0;
43
+ if ((prev[refKey] ?? 0) === next) return prev;
44
+ const copy = { ...prev };
45
+ if (next > 0) copy[refKey] = next;
46
+ else delete copy[refKey];
47
+ return copy;
48
+ });
49
+ },
50
+ [refKey, setPages],
51
+ );
52
+ return { page: pages[refKey] ?? 0, setPage };
53
+ }
54
+
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+
3
+ import { createElement, useMemo } from 'react';
4
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { panelTabRows } from '@terrafirmagreg-team/recipe/lib/panel';
7
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
8
+ import type { RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
9
+
10
+ export function usePanelTabs(
11
+ index: RecipeCompactIndex | null,
12
+ names: Record<string, Record<string, string>>,
13
+ lang: Lang,
14
+ ) {
15
+ const t = useTranslations();
16
+ return useMemo(
17
+ () => [
18
+ {
19
+ id: '',
20
+ icon: createElement(Entry, {
21
+ id: 'minecraft:compass',
22
+ kind: 'item',
23
+ size: 'lg',
24
+ href: false,
25
+ }),
26
+ help: t('All items', { note: 'recipe.all_items' }),
27
+ },
28
+ ...panelTabRows(index, names, lang).map((row) => ({
29
+ id: row.id,
30
+ icon: createElement(Entry, {
31
+ ...(row.iconRef
32
+ ? { reference: row.iconRef }
33
+ : { id: row.icon, kind: 'item' as const }),
34
+ size: 'lg',
35
+ href: false,
36
+ }),
37
+ help: row.help,
38
+ })),
39
+ ],
40
+ [index, lang, names, t],
41
+ );
42
+ }
43
+
@@ -0,0 +1,186 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { useEffect, useState } from 'react';
5
+ import { useLocationSearchParams } from '@terrafirmagreg-team/ui/hooks/page/use-location-search';
6
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
7
+ import {
8
+ recipeCalcHref,
9
+ recipeHref,
10
+ recipePlaceFromParams,
11
+ } from '@terrafirmagreg-team/recipe/lib/links';
12
+ import { canonicalStackId } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
13
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
14
+ import type { RecipeRelation } from '@terrafirmagreg-team/recipe/types';
15
+
16
+ function urlPage(params: URLSearchParams, key: string) {
17
+ const raw = Number.parseInt(params.get(key) || '1', 10);
18
+ return Number.isFinite(raw) && raw > 0 ? raw - 1 : 0;
19
+ }
20
+
21
+ function urlRelation(
22
+ params: URLSearchParams,
23
+ ): RecipeRelation | undefined {
24
+ const value = params.get('relation');
25
+ return value === 'uses' || value === 'tags' ? value : undefined;
26
+ }
27
+
28
+ export function useRecipeQuery(dataset: DatasetRef, lang: Lang) {
29
+ const params = useLocationSearchParams();
30
+
31
+ const place = recipePlaceFromParams(params);
32
+ const isCalc = place.kind === 'calc';
33
+ const isTool = place.kind !== 'type';
34
+ const rawItem = params.get('item') ?? undefined;
35
+ const rawFluid = params.get('fluid') ?? undefined;
36
+ const item = isTool ? undefined : rawItem;
37
+ const fluid = isTool || item ? undefined : rawFluid;
38
+ const recipeId = isCalc ? undefined : (params.get('id') ?? undefined);
39
+ const solo = isTool || !recipeId ? undefined : (params.get('solo') ?? undefined);
40
+ const relation = isTool ? undefined : urlRelation(params);
41
+ const tab = params.get('tab') ?? undefined;
42
+ const tree = isCalc ? (params.get('tree') ?? '') : undefined;
43
+ const isAlloy = place.kind === 'alloy';
44
+ const alloyUnit =
45
+ isAlloy && params.get('unit') === 'ingot' ? ('ingot' as const) : undefined;
46
+ const alloyMix = isAlloy ? (params.get('mix') ?? undefined) : undefined;
47
+ const searchParam = isTool ? '' : (params.get('search') ?? '');
48
+ const rpageValue = isTool ? 0 : urlPage(params, 'rpage');
49
+
50
+ const [query, setQuery] = useState(searchParam);
51
+ const [lastSearch, setLastSearch] = useState(searchParam);
52
+ if (lastSearch !== searchParam) {
53
+ setLastSearch(searchParam);
54
+ setQuery(searchParam);
55
+ }
56
+
57
+ useEffect(() => {
58
+ if (!isTool) return;
59
+ const stray = isCalc
60
+ ? params.get('type') ||
61
+ params.get('item') ||
62
+ params.get('fluid') ||
63
+ params.get('id') ||
64
+ params.get('solo') ||
65
+ params.get('relation') ||
66
+ params.get('search') ||
67
+ params.get('rpage') ||
68
+ params.get('unit') ||
69
+ params.get('mix')
70
+ : params.get('type') ||
71
+ params.get('item') ||
72
+ params.get('fluid') ||
73
+ params.get('relation') ||
74
+ params.get('search') ||
75
+ params.get('rpage') ||
76
+ params.get('solo') ||
77
+ params.get('tree') ||
78
+ (isAlloy ? null : params.get('unit') || params.get('mix'));
79
+ if (!stray) return;
80
+ replaceUrlState(
81
+ isCalc
82
+ ? recipeCalcHref(dataset, lang, tree || undefined)
83
+ : recipeHref(dataset, lang, {
84
+ tool: place.kind,
85
+ id: recipeId,
86
+ unit: alloyUnit,
87
+ mix: alloyMix,
88
+ tab,
89
+ }),
90
+ );
91
+ }, [
92
+ isTool,
93
+ isCalc,
94
+ place.kind,
95
+ lang,
96
+ dataset,
97
+ params,
98
+ tree,
99
+ recipeId,
100
+ tab,
101
+ isAlloy,
102
+ alloyUnit,
103
+ alloyMix,
104
+ ]);
105
+
106
+ useEffect(() => {
107
+ if (isTool) return;
108
+ if (rawItem && rawFluid) {
109
+ replaceUrlState(
110
+ recipeHref(dataset, lang, {
111
+ type: params.get('type') ?? undefined,
112
+ item: rawItem,
113
+ id: recipeId,
114
+ solo,
115
+ relation,
116
+ tab,
117
+ search: searchParam || undefined,
118
+ rpage: rpageValue + 1,
119
+ }),
120
+ );
121
+ }
122
+ }, [
123
+ isTool,
124
+ lang,
125
+ dataset,
126
+ params,
127
+ rawItem,
128
+ rawFluid,
129
+ recipeId,
130
+ solo,
131
+ relation,
132
+ tab,
133
+ searchParam,
134
+ rpageValue,
135
+ ]);
136
+
137
+ useEffect(() => {
138
+ if (isTool || (rawItem && rawFluid)) return;
139
+ const canonItem = rawItem ? canonicalStackId(rawItem) : undefined;
140
+ const canonFluid = rawFluid ? canonicalStackId(rawFluid) : undefined;
141
+ if (canonItem === rawItem && canonFluid === rawFluid) return;
142
+ replaceUrlState(
143
+ recipeHref(dataset, lang, {
144
+ type: params.get('type') ?? undefined,
145
+ item: canonItem,
146
+ fluid: canonFluid,
147
+ id: recipeId,
148
+ solo,
149
+ relation,
150
+ tab,
151
+ search: searchParam || undefined,
152
+ rpage: rpageValue + 1,
153
+ }),
154
+ );
155
+ }, [
156
+ isTool,
157
+ lang,
158
+ dataset,
159
+ params,
160
+ rawItem,
161
+ rawFluid,
162
+ recipeId,
163
+ solo,
164
+ relation,
165
+ tab,
166
+ searchParam,
167
+ rpageValue,
168
+ ]);
169
+
170
+ return {
171
+ place,
172
+ item,
173
+ fluid,
174
+ recipeId,
175
+ alloyUnit,
176
+ alloyMix,
177
+ solo,
178
+ relation,
179
+ tab,
180
+ tree,
181
+ query,
182
+ setQuery,
183
+ rpage: rpageValue,
184
+ };
185
+ }
186
+
@@ -0,0 +1,88 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useMemo } from 'react';
4
+ import { useVersionedDataset } from '@terrafirmagreg-team/kit/hooks/use-versioned-dataset';
5
+ import { useRecipeIndex } from '@terrafirmagreg-team/recipe/hooks/use-index';
6
+ import { useRecipeQuery } from '@terrafirmagreg-team/recipe/hooks/use-query';
7
+ import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
8
+ import { clientDumpLang } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
9
+ import { useRecipeIndexNames } from '@terrafirmagreg-team/recipe/lib/index-store';
10
+ import {
11
+ RECIPE_ALL_TYPE,
12
+ recipeHref,
13
+ recipePlaceOpts,
14
+ } from '@terrafirmagreg-team/recipe/lib/links';
15
+ import { recipeUsedItems } from '@terrafirmagreg-team/recipe/lib/used-items';
16
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
17
+ import type {
18
+ RecipeHrefOpts,
19
+ RecipePageData,
20
+ RecipeSession,
21
+ } from '@terrafirmagreg-team/recipe/types';
22
+
23
+ export function useRecipeSession(page: RecipePageData): RecipeSession {
24
+ const { dataset: id, lang } = page;
25
+ const dataset =
26
+ useVersionedDataset(id.id, { versions: page.versions }) ?? id;
27
+ const query = useRecipeQuery(dataset, lang);
28
+ const { index, indexLoading } = useRecipeIndex(dataset, lang);
29
+ const placeOpts = recipePlaceOpts(query.place);
30
+
31
+ const indexNames = useRecipeIndexNames(dataset);
32
+ const names = useMemo(
33
+ () => indexNames ?? index?.names ?? {},
34
+ [indexNames, index],
35
+ );
36
+ const langRaw = useAsyncValue(
37
+ () => clientDumpLang(dataset, lang),
38
+ [dataset, lang],
39
+ );
40
+ const langMap = useMemo(
41
+ () => ({ ...names.en_us, ...langRaw, ...names[lang] }),
42
+ [langRaw, names, lang],
43
+ );
44
+ const used = useMemo(() => recipeUsedItems(index), [index]);
45
+ const nav: RecipeHrefOpts = {
46
+ ...placeOpts,
47
+ tab: query.tab,
48
+ item: query.item,
49
+ fluid: query.fluid,
50
+ id: query.recipeId,
51
+ relation: query.relation,
52
+ search: query.query || undefined,
53
+ rpage: query.rpage + 1,
54
+ };
55
+
56
+ const firstType = useMemo(() => {
57
+ const counts = index?.typeCounts;
58
+ if (!counts) return undefined;
59
+ return index?.categories
60
+ ?.map((row) => row.id)
61
+ .find((id) => (counts[id] ?? 0) > 0);
62
+ }, [index]);
63
+ const bareIndex =
64
+ query.place.kind === 'type' &&
65
+ query.place.id === RECIPE_ALL_TYPE &&
66
+ !query.item &&
67
+ !query.fluid;
68
+ useEffect(() => {
69
+ if (!bareIndex || !firstType) return;
70
+ replaceUrlState(recipeHref(dataset, lang, { ...nav, type: firstType }));
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- nav rebuilds per render
72
+ }, [bareIndex, firstType, dataset, lang]);
73
+
74
+ return {
75
+ page,
76
+ dataset,
77
+ lang,
78
+ ...query,
79
+ placeOpts,
80
+ nav,
81
+ index,
82
+ indexLoading,
83
+ names,
84
+ langMap,
85
+ used,
86
+ };
87
+ }
88
+
@@ -0,0 +1,16 @@
1
+ import {
2
+ createStoredValue,
3
+ literalCodec,
4
+ } from '@terrafirmagreg-team/ui/lib/utils/stored-value';
5
+ import type { RecipeSidebarGroup } from '@terrafirmagreg-team/recipe/types';
6
+
7
+ const useStoredSidebarGroup = createStoredValue(
8
+ 'wiki.recipe.sidebarGroup',
9
+ literalCodec<RecipeSidebarGroup>(['flat', 'mod'], 'mod'),
10
+ );
11
+
12
+ export function useSidebarGroup() {
13
+ const [sidebarGroup, setSidebarGroup] = useStoredSidebarGroup();
14
+ return { sidebarGroup, setSidebarGroup };
15
+ }
16
+
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
5
+ import { loadAllTagMembers } from '@terrafirmagreg-team/recipe/lib/client-index';
6
+
7
+ export function useTagMembers(
8
+ dataset: DatasetRef,
9
+ enabled: boolean,
10
+ ): Record<string, string[]> | undefined {
11
+ return useAsyncValue(
12
+ enabled ? () => loadAllTagMembers(dataset) : false,
13
+ [dataset, enabled],
14
+ );
15
+ }
16
+
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
4
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
5
+ import { loadCategoryRecipes } from '@terrafirmagreg-team/recipe/lib/client-index';
6
+ import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
7
+
8
+ export function useToolRecipes<T>(
9
+ session: RecipeSession | null,
10
+ category: string,
11
+ parse: (recipe: Recipe) => T,
12
+ ): { value: T[] | undefined; pending: boolean } {
13
+ const index = session?.index;
14
+ const dataset = session?.dataset;
15
+
16
+ return useAsyncResult(
17
+ index && dataset
18
+ ? () =>
19
+ loadCategoryRecipes(dataset, index, category).then((recipes) =>
20
+ recipes.map(parse),
21
+ )
22
+ : undefined,
23
+ [dataset, index, category, parse],
24
+ );
25
+ }
26
+
@@ -0,0 +1,73 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useMemo } from 'react';
4
+ import { groupByCategory } from '@terrafirmagreg-team/recipe/lib/group';
5
+ import { TAG_RECIPE_TYPE } from '@terrafirmagreg-team/recipe/lib/client-index';
6
+ import { RECIPE_ALL_TYPE, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
7
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
8
+ import type {
9
+ RecipeCompactRow,
10
+ RecipeSession,
11
+ } from '@terrafirmagreg-team/recipe/types';
12
+
13
+ export function useTypeFilter(
14
+ session: Pick<
15
+ RecipeSession,
16
+ | 'dataset'
17
+ | 'lang'
18
+ | 'index'
19
+ | 'nav'
20
+ | 'place'
21
+ | 'item'
22
+ | 'fluid'
23
+ | 'recipeId'
24
+ >,
25
+ rows: RecipeCompactRow[],
26
+ ) {
27
+ const { dataset, lang, index, nav, place, recipeId } = session;
28
+ const groups = useMemo(
29
+ () => groupByCategory(rows, index?.types ?? [], index?.categories),
30
+ [rows, index],
31
+ );
32
+
33
+ const urlType =
34
+ place?.kind === 'type' && place.id !== RECIPE_ALL_TYPE
35
+ ? place.id
36
+ : undefined;
37
+ const valid = groups.some((group) => group.category === urlType)
38
+ ? urlType
39
+ : undefined;
40
+ const primary =
41
+ (recipeId
42
+ ? groups.find((group) => group.rows.some((row) => row.id === recipeId))
43
+ ?.category
44
+ : undefined) ??
45
+ groups.find((group) => group.category !== TAG_RECIPE_TYPE)?.category ??
46
+ groups[0]?.category;
47
+ const active = valid ?? primary ?? '';
48
+ const activeRows =
49
+ groups.find((group) => group.category === active)?.rows ?? [];
50
+
51
+ useEffect(() => {
52
+ if (!primary || valid) return;
53
+ replaceUrlState(
54
+ recipeHref(dataset, lang, { ...nav, type: primary, rpage: undefined }),
55
+ );
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- nav rebuilds per render
57
+ }, [primary, valid, dataset, lang]);
58
+
59
+ const setActive = (next: string) => {
60
+ if (next === active || next === urlType) return;
61
+ replaceUrlState(
62
+ recipeHref(dataset, lang, { ...nav, type: next, rpage: undefined }),
63
+ );
64
+ };
65
+
66
+ return {
67
+ ids: groups.map((group) => group.category),
68
+ active,
69
+ setActive,
70
+ rows: activeRows,
71
+ };
72
+ }
73
+