Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit dc234e5

Browse files
committed
Add button to show all pieces to the dialog
1 parent c373d10 commit dc234e5

File tree

6 files changed

+78
-24
lines changed

6 files changed

+78
-24
lines changed

components/calculationInput/common/PositiveIntegerOnlyInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ interface PositiveIntegerOnlyInputProps<T extends FieldValues> {
1111
helperText: string;
1212
min?: number;
1313
inputLabel?: string;
14+
focused?: boolean;
1415
}
1516

1617
const PositiveIntegerOnlyInput = function<T>({
1718
name, control, showError, helperText,
18-
min = 1, inputLabel,
19+
min = 1, inputLabel, focused,
1920
}: PositiveIntegerOnlyInputProps<T>) {
2021
const {t} = useTranslation('home');
2122
return <Controller
@@ -42,6 +43,7 @@ const PositiveIntegerOnlyInput = function<T>({
4243
render={({field}) => (
4344
<TextField
4445
{...field}
46+
inputRef={(elm) => elm && focused && elm.focus()}
4547
inputProps={{pattern: '\\d*'}}
4648
variant="outlined"
4749
error={showError}

components/calculationInput/equipments/inventory/AddToInventoryDialog.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import styles from './AddToInventoryDialog.module.scss';
22
import {
3+
Box,
34
Button, Dialog, DialogActions, DialogContent, DialogTitle,
5+
Stack,
6+
ToggleButton,
7+
ToggleButtonGroup,
48
useMediaQuery, useTheme,
59
} from '@mui/material';
6-
import React, {useEffect, useMemo, useReducer} from 'react';
10+
import React, {useEffect, useMemo, useReducer, useState} from 'react';
711
import {useTranslation} from 'next-i18next';
812
import {useForm} from 'react-hook-form';
913
import {
@@ -44,23 +48,30 @@ const AddToInventoryDialog = ({
4448
open && notifyOpened();
4549
}, [open]);
4650

47-
const pieceIds = useMemo(() => drops.map((drop) => drop.id), [drops]);
51+
const [mode, setMode] = useState<'all' | 'lack' | 'required'>('lack');
52+
4853
const pieces = useMemo(() => {
4954
// 20-3: Necklace, Watch, Bag
5055
// 20-4: Watch, Charm, Badge
5156
// 13-1: Shoes, Gloves, Hat
5257
// descending tier -> descending category order?
53-
return Array.from(piecesState.values())
54-
.filter((state) => pieceIds.includes(state.pieceId) && state.needCount > 0)
55-
.sort(buildComparator(
56-
(piece) => equipById.get(piece.pieceId),
57-
buildComparator((e) => e.tier, Comparators.numberDescending),
58-
buildComparator((e) => e.category, buildArrayIndexComparator(
59-
EquipmentCategories,
60-
SortingOrder.Descending
61-
)),
62-
));
63-
}, [piecesState, pieceIds, equipById]);
58+
return drops.map(({id}) => (piecesState.get(id) ?? {
59+
pieceId: id,
60+
needCount: 0,
61+
inStockCount: 0,
62+
})).filter((state) => ({
63+
all: true,
64+
lack: state.needCount < state.inStockCount,
65+
required: state.needCount > 0,
66+
}[mode])).sort(buildComparator(
67+
(piece) => equipById.get(piece.pieceId),
68+
buildComparator((e) => e.tier, Comparators.numberDescending),
69+
buildComparator((e) => e.category, buildArrayIndexComparator(
70+
EquipmentCategories,
71+
SortingOrder.Descending
72+
)),
73+
));
74+
}, [drops, piecesState, mode, equipById]);
6475
const defaultValues = useMemo(() => {
6576
return pieces.reduce<InventoryForm>((acc, piece) => {
6677
acc[piece.pieceId] = '';
@@ -102,26 +113,35 @@ const AddToInventoryDialog = ({
102113
return !onceOpen ? null : <Dialog open={open} keepMounted fullWidth
103114
fullScreen={hasManyPieces() && isFullScreen}
104115
maxWidth={hasManyPieces() && 'xl'}>
105-
<DialogTitle>獲得した設計図</DialogTitle>
116+
<Stack component={DialogTitle} direction='row' alignItems='center'>
117+
{t('addPieceDialog.addToInventory')}
118+
<Box flexGrow={1} />
119+
<ToggleButtonGroup exclusive size='small'
120+
value={mode} onChange={(e, value) => value && setMode(value)}>
121+
<ToggleButton value='all'>{t('piecesFilter.filter.all')}</ToggleButton>
122+
<ToggleButton value='lack'>{t('piecesFilter.filter.insufficient')}</ToggleButton>
123+
<ToggleButton value='required'>{t('piecesFilter.filter.required')}</ToggleButton>
124+
</ToggleButtonGroup>
125+
</Stack>
106126

107127
<DialogContent className={styles.dialogContentContainer}>
108128
<div className={styles.filler}></div>
109129
<div className={`${styles.container} ${isXsOrSmallerScreen && styles.xs}`}>
110-
{pieces.map((piece) => {
130+
{pieces.map((piece, index) => {
111131
return <ObtainedPieceBox key={piece.pieceId} allErrors={allErrors}
112132
control={control}
113133
equipmentsById={equipById}
114-
piece={piece}/>;
134+
piece={piece}
135+
focused={index === 0}/>;
115136
})}
116137
</div>
138+
{pieces.length === 0 && <div>{t('filterResultEmpty')}</div>}
117139
<div className={styles.filler}></div>
118140
</DialogContent>
119141

120142
<DialogActions>
121143
<Button onClick={handleCancelDialog}>{t('cancelButton')}</Button>
122-
<Button onClick={handleUpdateInventory} disabled={!isCountValid}>
123-
追加
124-
</Button>
144+
<Button onClick={handleUpdateInventory} disabled={!isCountValid}>{t('addButton')}</Button>
125145
</DialogActions>
126146
</Dialog>;
127147
};

components/calculationInput/equipments/inventory/ObtainedPieceBox.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ import React from 'react';
88
import {EquipmentsById} from 'components/calculationInput/PiecesCalculationCommonTypes';
99
import {PieceState} from 'components/calculationInput/equipments/inventory/PiecesInventory';
1010
import {Control} from 'react-hook-form/dist/types/form';
11-
import {InventoryForm} from 'components/calculationInput/equipments/inventory/InventoryUpdateDialog';
11+
import {InventoryForm}
12+
from 'components/calculationInput/equipments/inventory/InventoryUpdateDialog';
1213
import {useTranslation} from 'next-i18next';
1314

1415
const ObtainedPieceBox = function({
1516
equipmentsById,
1617
piece,
1718
control,
1819
allErrors,
20+
focused,
1921
}: {
2022
equipmentsById: EquipmentsById,
2123
piece: PieceState,
2224
control: Control<InventoryForm>,
2325
allErrors: any,
26+
focused?: boolean,
2427
}) {
2528
const {t} = useTranslation('home');
2629

@@ -38,7 +41,7 @@ const ObtainedPieceBox = function({
3841
</Card>
3942
<Box sx={{mr: 2}}/>
4043
<PositiveIntegerOnlyInput name={piece.pieceId}
41-
min={0}
44+
min={0} focused={focused}
4245
control={control} showError={!!allErrors[piece.pieceId]}
4346
helperText={allErrors[piece.pieceId]?.message ?? ''}
4447
inputLabel={t('addPieceDialog.obtainedCount')} />

public/locales/en/home.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"minimumIs": "Minimum is {{min}}",
2222
"maximumIs": "Maximum is {{max}}",
2323
"quantity": "Quantity",
24-
"inStockCount": "In Stock Number"
24+
"inStockCount": "In Stock Number",
25+
"addToInventory": "Acquired Pieces",
26+
"obtainedCount": "Acquisitions"
2527
},
2628
"selectInputMode": "Select input mode",
2729
"selectResultMode": "Output Mode",
@@ -46,6 +48,14 @@
4648
"enterNickName": "Enter a nickname(optional)",
4749
"enterNickNameNormalHelperText": "Enter a student name to help you memorize equipment ownership"
4850
},
51+
"filterResultEmpty": "Could not find any equipment matching the filter.",
52+
"piecesFilter": {
53+
"filter": {
54+
"required": "Required",
55+
"insufficient": "Insufficient",
56+
"all": "All"
57+
}
58+
},
4959
"thinsToNote": {
5060
"title": "Things to note",
5161
"pointThisIsEstimation": "Recommended sweeping times is an estimation and your mileage may vary.",

public/locales/ja/home.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"maximumIs": "最大値は{{max}}です",
2323
"quantity": "欲しい数",
2424
"inStockCount": "所持数",
25+
"addToInventory": "獲得した設計図",
2526
"obtainedCount": "獲得数"
2627
},
2728
"selectInputMode": "入力モード",
@@ -46,6 +47,14 @@
4647
"enterNickName": "ニックネーム入力(任意)",
4748
"enterNickNameNormalHelperText": "生徒の名前をメモとして入力すれば、装備の管理ができます"
4849
},
50+
"filterResultEmpty": "条件に合う装備が見つかりません。",
51+
"piecesFilter": {
52+
"filter": {
53+
"required": "必要",
54+
"insufficient": "不足",
55+
"all": "すべて"
56+
}
57+
},
4958
"thinsToNote": {
5059
"title": "注記",
5160
"pointThisIsEstimation": "推奨掃討回数は予測であり、実際の報酬と大きく異なる場合もあります。",

public/locales/zh/home.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"minimumIs": "不能小于{{min}}",
2222
"maximumIs": "不能大于{{max}}",
2323
"quantity": "数量",
24-
"inStockCount": "库存数量"
24+
"inStockCount": "库存数量",
25+
"addToInventory": "获得设计图",
26+
"obtainedCount": "收购数量"
2527
},
2628
"selectInputMode": "输入模式",
2729
"selectResultMode": "结果展示模式",
@@ -45,6 +47,14 @@
4547
"enterNickName": "添加昵称(选填)",
4648
"enterNickNameNormalHelperText": "可以输入学生姓名方便记和进行装备管理"
4749
},
50+
"filterResultEmpty": "我找不到符合要求的设备。",
51+
"piecesFilter": {
52+
"filter": {
53+
"required": "所需",
54+
"insufficient": "不足",
55+
"all": "全部"
56+
}
57+
},
4858
"thinsToNote": {
4959
"title": "注意事项",
5060
"pointThisIsEstimation": "推荐扫图次数为估计,与实际可能有出入。",

0 commit comments

Comments
 (0)