Skip to content

Commit 99b41fe

Browse files
committed
fix(AddModal): data is lost when switching tabs in bulk mode resolve #43
1 parent 29bdbc6 commit 99b41fe

7 files changed

Lines changed: 114 additions & 111 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,17 @@ jobs:
156156
$target = "${{ matrix.rust_target }}"
157157
$portableRoot = "src-tauri/target/$target/release/portable/ReinaManager-$version-$short"
158158
$resourcesDataDir = Join-Path $portableRoot "resources/data"
159-
$zipPath = "src-tauri/target/$target/release/ReinaManager-$version-$short-portable.zip"
160159
161160
if (Test-Path $portableRoot) {
162161
Remove-Item $portableRoot -Recurse -Force
163162
}
164-
if (Test-Path $zipPath) {
165-
Remove-Item $zipPath -Force
166-
}
167163
168164
New-Item -ItemType Directory -Path $resourcesDataDir -Force | Out-Null
169165
@"
170166
该文件夹为数据库文件夹,删除该文件夹则退出便携模式,反之则保持便携模式。
171167
This folder stores the database. Deleting this folder exits portable mode; keeping it preserves portable mode.
172168
"@ | Set-Content -Path (Join-Path $resourcesDataDir "readme.txt") -Encoding UTF8
173169
Copy-Item "src-tauri/target/$target/release/ReinaManager.exe" "$portableRoot/ReinaManager.exe"
174-
Compress-Archive -Path "$portableRoot/*" -DestinationPath $zipPath
175170
176171
# 显示构建状态
177172
- name: Build status
@@ -190,7 +185,7 @@ jobs:
190185
uses: actions/upload-artifact@v6
191186
with:
192187
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-portable
193-
path: src-tauri/target/${{ matrix.rust_target }}/release/ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-portable.zip
188+
path: src-tauri/target/${{ matrix.rust_target }}/release/portable/ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}
194189
if-no-files-found: warn
195190

196191
- name: Upload MSI Installer (Artifact)

src/components/AddModal/AddModal.tsx

Lines changed: 103 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -416,112 +416,117 @@ const AddModal: React.FC = () => {
416416
: { pt: 2 }
417417
}
418418
>
419-
{activeTab === "single" ? (
420-
<Stack spacing={2} sx={{ pt: 1 }}>
421-
{/* 选择本地可执行文件 */}
422-
<Button
423-
fullWidth
424-
variant="contained"
425-
onClick={async () => {
426-
const result = await handleExeFile();
427-
if (result) setAddModalPath(result);
428-
}}
429-
startIcon={<FileOpenIcon />}
430-
disabled={isBusy}
431-
>
432-
{t("components.AddModal.selectLauncher")}
433-
</Button>
434-
<TextField
435-
fullWidth
436-
size="small"
437-
value={addModalPath}
438-
placeholder={t("components.AddModal.dragHint")}
439-
InputProps={{ readOnly: true }}
419+
{/* single tab 内容:通过 display 控制显隐,避免切换 tab 时卸载 */}
420+
<Stack
421+
spacing={2}
422+
sx={{ pt: 1, display: activeTab === "single" ? undefined : "none" }}
423+
>
424+
{/* 选择本地可执行文件 */}
425+
<Button
426+
fullWidth
427+
variant="contained"
428+
onClick={async () => {
429+
const result = await handleExeFile();
430+
if (result) setAddModalPath(result);
431+
}}
432+
startIcon={<FileOpenIcon />}
433+
disabled={isBusy}
434+
>
435+
{t("components.AddModal.selectLauncher")}
436+
</Button>
437+
<TextField
438+
fullWidth
439+
size="small"
440+
value={addModalPath}
441+
placeholder={t("components.AddModal.dragHint")}
442+
InputProps={{ readOnly: true }}
443+
/>
444+
{/* 自定义模式和 API 来源切换 */}
445+
<Stack spacing={1}>
446+
<FormControlLabel
447+
control={
448+
<Switch
449+
checked={customMode}
450+
onChange={() => {
451+
setCustomMode(!customMode);
452+
}}
453+
disabled={isBusy}
454+
/>
455+
}
456+
label={t("components.AddModal.enableCustomMode")}
440457
/>
441-
{/* 自定义模式和 API 来源切换 */}
442-
<Stack spacing={1}>
458+
<RadioGroup
459+
row
460+
value={apiSource}
461+
sx={{ gap: 1 }}
462+
onChange={(e) =>
463+
setApiSource(
464+
e.target.value as "bgm" | "vndb" | "ymgal" | "mixed",
465+
)
466+
}
467+
>
443468
<FormControlLabel
444-
control={
445-
<Switch
446-
checked={customMode}
447-
onChange={() => {
448-
setCustomMode(!customMode);
449-
}}
450-
disabled={isBusy}
451-
/>
452-
}
453-
label={t("components.AddModal.enableCustomMode")}
469+
value="bgm"
470+
control={<Radio />}
471+
label="Bangumi"
472+
disabled={isBusy}
454473
/>
455-
<RadioGroup
456-
row
457-
value={apiSource}
458-
sx={{ gap: 1 }}
459-
onChange={(e) =>
460-
setApiSource(
461-
e.target.value as "bgm" | "vndb" | "ymgal" | "mixed",
462-
)
463-
}
464-
>
465-
<FormControlLabel
466-
value="bgm"
467-
control={<Radio />}
468-
label="Bangumi"
469-
disabled={isBusy}
470-
/>
471-
<FormControlLabel
472-
value="vndb"
473-
control={<Radio />}
474-
label="VNDB"
475-
disabled={isBusy}
476-
/>
477-
<FormControlLabel
478-
value="ymgal"
479-
control={<Radio />}
480-
label="YMGal"
481-
disabled={isBusy}
482-
/>
483-
<FormControlLabel
484-
value="mixed"
485-
control={<Radio />}
486-
label="Mixed"
487-
disabled={isBusy}
488-
/>
489-
</RadioGroup>
490474
<FormControlLabel
491-
control={
492-
<Switch
493-
checked={isID}
494-
onChange={() => {
495-
setisID(!isID);
496-
}}
497-
disabled={isBusy}
498-
/>
499-
}
500-
label={t("components.AddModal.idSearch")}
475+
value="vndb"
476+
control={<Radio />}
477+
label="VNDB"
478+
disabled={isBusy}
501479
/>
502-
</Stack>
503-
{/* 游戏名称输入框 */}
504-
<TextField
505-
required
506-
size="small"
507-
id="name"
508-
name="game-name"
509-
label={
510-
!isID
511-
? t("components.AddModal.gameName")
512-
: t("components.AddModal.gameIDTips")
480+
<FormControlLabel
481+
value="ymgal"
482+
control={<Radio />}
483+
label="YMGal"
484+
disabled={isBusy}
485+
/>
486+
<FormControlLabel
487+
value="mixed"
488+
control={<Radio />}
489+
label="Mixed"
490+
disabled={isBusy}
491+
/>
492+
</RadioGroup>
493+
<FormControlLabel
494+
control={
495+
<Switch
496+
checked={isID}
497+
onChange={() => {
498+
setisID(!isID);
499+
}}
500+
disabled={isBusy}
501+
/>
513502
}
514-
type="text"
515-
fullWidth
516-
variant="outlined"
517-
autoComplete="off"
518-
value={formText}
519-
onChange={(event) => setFormText(event.target.value)}
503+
label={t("components.AddModal.idSearch")}
520504
/>
521505
</Stack>
522-
) : (
523-
<BulkImportTab open={addModalOpen} onClose={handleCloseModal} />
524-
)}
506+
{/* 游戏名称输入框 */}
507+
<TextField
508+
required
509+
size="small"
510+
id="name"
511+
name="game-name"
512+
label={
513+
!isID
514+
? t("components.AddModal.gameName")
515+
: t("components.AddModal.gameIDTips")
516+
}
517+
type="text"
518+
fullWidth
519+
variant="outlined"
520+
autoComplete="off"
521+
value={formText}
522+
onChange={(event) => setFormText(event.target.value)}
523+
/>
524+
</Stack>
525+
{/* bulk tab:始终挂载,通过 hidden prop 控制显隐,保持状态在 tab 切换时不丢失 */}
526+
<BulkImportTab
527+
hidden={activeTab !== "bulk"}
528+
onClose={handleCloseModal}
529+
/>
525530
</DialogContent>
526531
{activeTab === "single" && (
527532
<DialogActions>

src/components/AddModal/BulkImportTab.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ interface ImportItem extends ScanResult {
5252
}
5353

5454
interface BulkImportTabProps {
55-
open: boolean;
55+
// 控制此 tab 是否隐藏(通过 CSS display:none 而非卸载)
56+
hidden: boolean;
5657
onClose: () => void;
5758
}
5859

@@ -83,7 +84,7 @@ function getMatchedGameName(
8384
);
8485
}
8586

86-
const BulkImportTab = ({ open, onClose }: BulkImportTabProps) => {
87+
const BulkImportTab = ({ hidden, onClose }: BulkImportTabProps) => {
8788
const { t, i18n } = useTranslation();
8889
const { data: bgmToken = "" } = useBgmToken();
8990
const { addGamesFromBulkImport, isAddingGames } = useBulkGameAddActions();
@@ -133,7 +134,7 @@ const BulkImportTab = ({ open, onClose }: BulkImportTabProps) => {
133134
if (!open) {
134135
resetState();
135136
}
136-
}, [open, resetState]);
137+
}, [resetState]);
137138

138139
const handleCloseSearchResult = useCallback(() => {
139140
setSearchResultState({ open: false, results: [] });
@@ -421,6 +422,8 @@ const BulkImportTab = ({ open, onClose }: BulkImportTabProps) => {
421422
height: "100%",
422423
minHeight: 0,
423424
overflow: "hidden",
425+
// 通过 CSS 控制显隐而非卸载,保持状态在 tab 切换时不丢失
426+
display: hidden ? "none" : undefined,
424427
}}
425428
>
426429
<Stack

src/locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,4 @@
644644
"minutesAgo_other": "{{count}} minutes ago"
645645
}
646646
}
647-
}
647+
}

src/locales/ja-JP.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,4 @@
637637
"minutesAgo_other": "{{count}}分前"
638638
}
639639
}
640-
}
640+
}

src/locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,4 @@
637637
"minutesAgo": "{{count}}分钟前"
638638
}
639639
}
640-
}
640+
}

src/locales/zh-TW.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,4 @@
637637
"minutesAgo_other": "{{count}}分鐘前"
638638
}
639639
}
640-
}
640+
}

0 commit comments

Comments
 (0)