@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.
- package/package.json +62 -3
- package/src/components/button-copy.tsx +43 -0
- package/src/components/cards/card/index.tsx +214 -0
- package/src/components/cards/card/scene.tsx +107 -0
- package/src/components/cards/card/strip.tsx +198 -0
- package/src/components/cards/card/text.tsx +46 -0
- package/src/components/cards/card/tips.tsx +63 -0
- package/src/components/cards/default-item.tsx +47 -0
- package/src/components/cards/glare-filter.tsx +29 -0
- package/src/components/cards/paged-card.tsx +222 -0
- package/src/components/cards/slot-hitbox.tsx +213 -0
- package/src/components/cards/strip-card/buttons.tsx +106 -0
- package/src/components/cards/strip-card/index.tsx +214 -0
- package/src/components/cards/strip-card/member-cell.tsx +167 -0
- package/src/components/cards/strip-card/sprite.tsx +36 -0
- package/src/components/embed-card.tsx +44 -0
- package/src/components/mdx/recipe.tsx +129 -0
- package/src/components/tool-list.tsx +49 -0
- package/src/components/tree.tsx +98 -0
- package/src/components/views/alloy/index.tsx +112 -0
- package/src/components/views/alloy/list.tsx +85 -0
- package/src/components/views/alloy/mix/index.tsx +35 -0
- package/src/components/views/alloy/mix/ratio.tsx +94 -0
- package/src/components/views/alloy/mix/rows.tsx +145 -0
- package/src/components/views/alloy/mix/status.tsx +122 -0
- package/src/components/views/alloy/mix/total.tsx +132 -0
- package/src/components/views/alloy/range-bar.tsx +65 -0
- package/src/components/views/alloy/stack-bar.tsx +88 -0
- package/src/components/views/browser/axis-switcher.tsx +54 -0
- package/src/components/views/browser/card-grid.tsx +275 -0
- package/src/components/views/browser/favorite-button.tsx +46 -0
- package/src/components/views/browser/frame.tsx +112 -0
- package/src/components/views/browser/index.tsx +114 -0
- package/src/components/views/browser/item-panel/index.tsx +229 -0
- package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
- package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
- package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
- package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
- package/src/components/views/browser/item-view/index.tsx +186 -0
- package/src/components/views/browser/item-view/tags.tsx +85 -0
- package/src/components/views/browser/item-view-header.tsx +131 -0
- package/src/components/views/browser/pane-tabs.tsx +61 -0
- package/src/components/views/browser/place-header.tsx +72 -0
- package/src/components/views/browser/query-controls.tsx +105 -0
- package/src/components/views/browser/recipe-item-header.tsx +60 -0
- package/src/components/views/browser/settings.tsx +52 -0
- package/src/components/views/browser/toolbar.tsx +54 -0
- package/src/components/views/browser/type-tabs.tsx +71 -0
- package/src/components/views/browser/type-view.tsx +184 -0
- package/src/components/views/browser/workstation-rail.tsx +43 -0
- package/src/components/views/calc/calculator/actions.tsx +47 -0
- package/src/components/views/calc/calculator/help.tsx +189 -0
- package/src/components/views/calc/calculator/index.tsx +172 -0
- package/src/components/views/calc/dot-overlay.tsx +80 -0
- package/src/components/views/calc/edge.tsx +152 -0
- package/src/components/views/calc/flow/index.tsx +305 -0
- package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
- package/src/components/views/calc/flow/toolbar.tsx +60 -0
- package/src/components/views/calc/flow/view-menu.tsx +117 -0
- package/src/components/views/calc/member-picker.tsx +120 -0
- package/src/components/views/calc/node-card/actions.tsx +90 -0
- package/src/components/views/calc/node-card/badges.tsx +59 -0
- package/src/components/views/calc/node-card/chips.tsx +187 -0
- package/src/components/views/calc/node-card/far.tsx +123 -0
- package/src/components/views/calc/node-card/full.tsx +332 -0
- package/src/components/views/calc/node-card/index.tsx +27 -0
- package/src/components/views/calc/node-card/menu.tsx +282 -0
- package/src/components/views/calc/node-card/port-cells.tsx +186 -0
- package/src/components/views/calc/node-card/port-rails.tsx +251 -0
- package/src/components/views/calc/node-card/ports.tsx +86 -0
- package/src/components/views/calc/recipe-picker/body.tsx +207 -0
- package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
- package/src/components/views/calc/recipe-picker/index.tsx +52 -0
- package/src/components/views/calc/sidebar.tsx +171 -0
- package/src/components/views/calc/trees/icon-picker.tsx +97 -0
- package/src/components/views/calc/trees/index.tsx +134 -0
- package/src/components/views/calc/trees/label.tsx +67 -0
- package/src/components/views/calc/trees/rows.tsx +140 -0
- package/src/components/views/forge/gui.tsx +131 -0
- package/src/components/views/forge/index.tsx +112 -0
- package/src/components/views/forge/list.tsx +113 -0
- package/src/components/views/forge/workbench/controls.tsx +103 -0
- package/src/components/views/forge/workbench/index.tsx +85 -0
- package/src/components/views/forge/workbench/panel.tsx +228 -0
- package/src/components/views/forge/workbench/ruler.tsx +133 -0
- package/src/components/views/forge/workbench/status.tsx +55 -0
- package/src/components/views/forge/workbench/tape.tsx +70 -0
- package/src/hooks/alloy/use-fluid-colors.ts +125 -0
- package/src/hooks/alloy/use-mix-state.ts +240 -0
- package/src/hooks/calc/flow/use-engage.ts +129 -0
- package/src/hooks/calc/flow/use-handlers.ts +192 -0
- package/src/hooks/calc/flow/use-layout.ts +105 -0
- package/src/hooks/calc/flow/use-mount.ts +97 -0
- package/src/hooks/calc/flow/use-nodes.ts +260 -0
- package/src/hooks/calc/flow/use-pickers.ts +57 -0
- package/src/hooks/calc/flow/use-viewport.ts +141 -0
- package/src/hooks/calc/flow/use-window.ts +87 -0
- package/src/hooks/calc/use-actions.ts +355 -0
- package/src/hooks/calc/use-amounts.ts +64 -0
- package/src/hooks/calc/use-data.ts +203 -0
- package/src/hooks/calc/use-defaults.ts +40 -0
- package/src/hooks/calc/use-far-mode.ts +37 -0
- package/src/hooks/calc/use-focus.ts +31 -0
- package/src/hooks/calc/use-maps.ts +76 -0
- package/src/hooks/calc/use-reset.ts +15 -0
- package/src/hooks/calc/use-resolver.ts +70 -0
- package/src/hooks/calc/use-session.ts +13 -0
- package/src/hooks/calc/use-share.ts +64 -0
- package/src/hooks/calc/use-storage.ts +126 -0
- package/src/hooks/calc/use-tier.ts +13 -0
- package/src/hooks/calc/use-view-mode.ts +24 -0
- package/src/hooks/calc/use-worker.ts +204 -0
- package/src/hooks/forge/use-anvil-gui.ts +16 -0
- package/src/hooks/forge/use-forge-state.ts +135 -0
- package/src/hooks/forge/use-ruler.ts +100 -0
- package/src/hooks/use-add-to-calc.ts +51 -0
- package/src/hooks/use-categories-by-id.ts +18 -0
- package/src/hooks/use-favorite-hotkey.ts +39 -0
- package/src/hooks/use-favorites.ts +135 -0
- package/src/hooks/use-group-outlines.ts +65 -0
- package/src/hooks/use-hide-unused.ts +12 -0
- package/src/hooks/use-index.ts +72 -0
- package/src/hooks/use-item-feeds.ts +46 -0
- package/src/hooks/use-item-pane.ts +106 -0
- package/src/hooks/use-item-press.ts +89 -0
- package/src/hooks/use-item-tag-groups.ts +54 -0
- package/src/hooks/use-item-tooltips.ts +18 -0
- package/src/hooks/use-left-sidebar-tree.ts +34 -0
- package/src/hooks/use-mod-names.ts +17 -0
- package/src/hooks/use-mount-limit.ts +22 -0
- package/src/hooks/use-panel-cells.ts +117 -0
- package/src/hooks/use-panel-page.ts +54 -0
- package/src/hooks/use-panel-tabs.ts +43 -0
- package/src/hooks/use-query.ts +186 -0
- package/src/hooks/use-session.ts +88 -0
- package/src/hooks/use-sidebar-group.ts +16 -0
- package/src/hooks/use-tag-members.ts +16 -0
- package/src/hooks/use-tool-recipes.ts +26 -0
- package/src/hooks/use-type-filter.ts +73 -0
- package/src/lib/alloy/mix.ts +210 -0
- package/src/lib/alloy/parse.ts +37 -0
- package/src/lib/calc/defaults.ts +47 -0
- package/src/lib/calc/flow.ts +315 -0
- package/src/lib/calc/focus.ts +15 -0
- package/src/lib/calc/meta.ts +17 -0
- package/src/lib/calc/pack.ts +77 -0
- package/src/lib/calc/ports.ts +43 -0
- package/src/lib/calc/resolve.ts +198 -0
- package/src/lib/calc/route/buckets.ts +49 -0
- package/src/lib/calc/route/geometry.ts +51 -0
- package/src/lib/calc/route/index.ts +3 -0
- package/src/lib/calc/route/polyline.ts +103 -0
- package/src/lib/calc/route/router.ts +394 -0
- package/src/lib/calc/scheme.ts +226 -0
- package/src/lib/calc/storage/entry.ts +97 -0
- package/src/lib/calc/storage/index.ts +20 -0
- package/src/lib/calc/storage/keys.ts +38 -0
- package/src/lib/calc/storage/store.ts +198 -0
- package/src/lib/calc/tree/index.ts +4 -0
- package/src/lib/calc/tree/materials.ts +29 -0
- package/src/lib/calc/tree/recipe.ts +104 -0
- package/src/lib/calc/tree/share.ts +135 -0
- package/src/lib/calc/worker/api.ts +25 -0
- package/src/lib/calc/worker/fetch.ts +66 -0
- package/src/lib/calc/worker/flush.ts +39 -0
- package/src/lib/calc/worker/index.ts +8 -0
- package/src/lib/calc/worker/protocol.ts +35 -0
- package/src/lib/calc/worker/resolve.ts +49 -0
- package/src/lib/calc/worker/state.ts +48 -0
- package/src/lib/card-model.ts +65 -0
- package/src/lib/client/recipe-categories.ts +14 -0
- package/src/lib/client/recipe.ts +85 -0
- package/src/lib/client-index/catalog.ts +91 -0
- package/src/lib/client-index/chrome.ts +180 -0
- package/src/lib/client-index/index.ts +20 -0
- package/src/lib/client-index/registry.ts +121 -0
- package/src/lib/client-index/rows.ts +260 -0
- package/src/lib/client-index/tooltips.ts +74 -0
- package/src/lib/config.ts +18 -0
- package/src/lib/data/category/dto.ts +25 -0
- package/src/lib/data/category/load.ts +47 -0
- package/src/lib/data/category/parse.ts +71 -0
- package/src/lib/data/dto.ts +152 -0
- package/src/lib/data/grid.ts +40 -0
- package/src/lib/data/parse/entry.ts +85 -0
- package/src/lib/data/parse/index.ts +3 -0
- package/src/lib/data/parse/layout.ts +138 -0
- package/src/lib/data/parse/slots.ts +85 -0
- package/src/lib/data/parse/widgets.ts +81 -0
- package/src/lib/data/scene.ts +103 -0
- package/src/lib/data/slot-io.ts +44 -0
- package/src/lib/dump.ts +6 -0
- package/src/lib/embed.ts +22 -0
- package/src/lib/favorite-hover.ts +13 -0
- package/src/lib/fluid-outputs.ts +70 -0
- package/src/lib/forge/actions.ts +59 -0
- package/src/lib/forge/data.ts +51 -0
- package/src/lib/forge/solve.ts +80 -0
- package/src/lib/group.ts +23 -0
- package/src/lib/index-store.ts +70 -0
- package/src/lib/links.ts +131 -0
- package/src/lib/lookup.ts +119 -0
- package/src/lib/panel-outline.ts +86 -0
- package/src/lib/panel.ts +105 -0
- package/src/lib/preview.ts +32 -0
- package/src/lib/recipe-slots.ts +8 -0
- package/src/lib/search.ts +139 -0
- package/src/lib/sidebar.ts +47 -0
- package/src/lib/used-items.ts +25 -0
- package/src/locales/en_us.json +172 -0
- package/src/locales/ru_ru.json +172 -0
- package/src/locales.ts +6 -0
- package/src/types/alloy.ts +20 -0
- package/src/types/calc-flow-props.ts +44 -0
- package/src/types/calc.ts +92 -0
- package/src/types/forge.ts +21 -0
- package/src/types/index.ts +136 -0
- package/styles/calc.css +308 -0
- package/styles/strip.css +7 -0
- package/styles.css +2 -0
- 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
|
+
|