feat(saves): edit local save nicknames and premium days

Let the launcher update a save's account nickname and replace or clear its remaining premium time. Reuse registration validation and preserve the existing login and password hash.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 17:41:46 +08:00
1 parent 1d3af395c2
commit d20b7f4249
13 files changed
+127 -19

No files matched your search

@@ -354,6 +354,7 @@
"battles": "Recorded battles",
"lastBattle": "Last battle",
"premiumDays": "Premium account days",
"saveAccount": "Save account details",
"apply": "Save changes",
"saved": "Changes saved.",
"noBattles": "The save has no recorded battles.",
@@ -354,6 +354,7 @@
"battles": "已记录对局",
"lastBattle": "上次对局",
"premiumDays": "高级账户剩余天数",
"saveAccount": "保存账号信息",
"apply": "保存更改",
"saved": "更改已保存。",
"noBattles": "此存档没有对局记录。",
@@ -1,7 +1,7 @@
import { useEffect, useState, type FormEvent } from 'react';
import { useTranslation } from 'react-i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import type { CurrencyEdits, SaveDetails, SaveList, SaveTransfer } from '@shared/schemas/saves.ts';
import type { AccountEdits, CurrencyEdits, SaveDetails, SaveList, SaveTransfer } from '@shared/schemas/saves.ts';
import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
@@ -103,6 +103,24 @@ export function SavesPage({ copy, copies, section, readOnly, onError }: SavesPag
.finally(() => setSaving(false));
};
const submitAccount = (event: FormEvent<HTMLFormElement>): void => {
event.preventDefault();
if (!details || !userId) return;
const data = new FormData(event.currentTarget);
const nick = String(data.get('nick') ?? '').trim();
const days = String(data.get('premiumDays') ?? '').trim();
const edits: AccountEdits = {};
if (nick !== details.save.nick) edits.nick = nick;
if (days !== '' && Number(days) !== details.save.premiumDays) edits.premiumDays = Number(days);
if (Object.keys(edits).length === 0) return;
setSaving(true);
setMessage('');
ipcInvoke('saves:editAccount', { copyId: copy.id, userId, edits })
.then((updated) => { updateDetails(updated); setMessage(t('saves.saved')); })
.catch(onError)
.finally(() => setSaving(false));
};
const title = t(`saves.sections.${section}`);
if (section === 'list') {
return (
@@ -213,7 +231,16 @@ export function SavesPage({ copy, copies, section, readOnly, onError }: SavesPag
<>
{readOnly && <p className="small">{t('saves.readOnly')}</p>}
<Row label={t('saves.login')}>{save.login}</Row>
<Row label={t('saves.premiumDays')}>{format.format(save.premiumDays)}</Row>
<form key={save.userId + ':' + save.nick + ':' + save.premiumDays} onSubmit={submitAccount}>
<Row label={t('saves.nick')}>
<input className="input" aria-label={t('saves.nick')} name="nick" defaultValue={save.nick} disabled={readOnly || saving} required />
</Row>
<Row label={t('saves.premiumDays')}>
<input className="input" aria-label={t('saves.premiumDays')} type="number" min="0" step="1"
name="premiumDays" defaultValue={save.premiumDays} disabled={readOnly || saving} />
</Row>
<button type="submit" className="button" disabled={readOnly || saving}>{t('saves.saveAccount')}</button>
</form>
<Row label={t('saves.vehicles')}>{format.format(save.vehicleCount)}</Row>
<Row label={t('saves.battles')}>{format.format(save.battleCount)}</Row>
<form key={save.userId} onSubmit={submitEdits}>