changed style of SaveFileUploadingDialog

This commit is contained in:
Altair-sh 2025-05-23 02:57:49 +05:00
parent 42adeb290c
commit 95880ca080
4 changed files with 46 additions and 26 deletions

View File

@ -15,7 +15,6 @@ html,
body { body {
max-width: 100vw; max-width: 100vw;
overflow-x: hidden; overflow-x: hidden;
padding: 10px;
} }
body { body {

View File

@ -9,6 +9,9 @@ export enum GameEnum {
Stellaris = 'stellaris', Stellaris = 'stellaris',
} }
//TODO: move to separate page
//TODO: add redirect to ?id={id} to see status of long parsing save
export default function SaveFileUploadingDialog() { export default function SaveFileUploadingDialog() {
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [selectedFile, setSelectedFile] = useState<File | null>(null) const [selectedFile, setSelectedFile] = useState<File | null>(null)
@ -27,7 +30,8 @@ export default function SaveFileUploadingDialog() {
} }
} }
const handleUpload = async () => { const handleUpload = async (e: React.FormEvent) => {
e.preventDefault()
setError(null) setError(null)
setUploadDisabled(true) setUploadDisabled(true)
try { try {
@ -70,40 +74,54 @@ export default function SaveFileUploadingDialog() {
return ( return (
<div className="container mt-5" style={{ maxWidth: '500px' }}> <div className="container mt-5" style={{ maxWidth: '500px' }}>
<h3 className="mb-2 fw-semibold">Select game save file</h3>
<FormError message={error} /> <FormError message={error} />
<div className="row align-items-center mb-3"> <form onSubmit={handleUpload} className="text-start">
<div className="col-auto">Select Game</div> <label htmlFor="gameSelect" className="form-label">
<select id="gameSelect" className="col-auto" value={game} onChange={handleGameSelect}> Select Game
</label>
<select
id="gameSelect"
name="gameSelect"
className="form-select mb-3"
value={game}
onChange={handleGameSelect}
required
>
{gameEnumOptions} {gameEnumOptions}
</select> </select>
</div>
<div className="row align-items-center mb-3"> <label htmlFor="fileInput" className="form-label">
<div className="col-auto">File</div> Select File
<input id="fileInput" type="file" className="col-auto" onChange={handleFileChange} /> </label>
</div> <input id="fileInput" type="file" className="form-control mb-3" onChange={handleFileChange} />
<button className="btn btn-primary" onClick={handleUpload} disabled={!selectedFile || uploadDisabled}> <button
className="btn btn-primary w-100 mt-1 mb-3"
type="submit"
disabled={!selectedFile || uploadDisabled}
>
Upload File Upload File
</button> </button>
</form>
<div className="container mt-5 text-center">
{/* TODO: extract this to a component {/* TODO: extract this to a component
<ConditionalView cond={uploadResult}> <LabeledValue val={}/> </ConditionalView> */} <ConditionalView cond={uploadResult}> <LabeledValue val={}/> </ConditionalView> */}
{uploadResult && ( {uploadResult && (
<div className="mt-3"> <div className="mb-3">
Save Id: <strong>{uploadResult.id}</strong> Save Id: <strong>{uploadResult.id}</strong>
</div> </div>
)} )}
{saveStatus && ( {saveStatus && (
<div className="mt-3"> <div className="mb-3">
Status: <strong>{saveStatus.status}</strong> Status: <strong>{saveStatus.status}</strong>
</div> </div>
)} )}
{/* add link to <ConditionalView cond={done}> /browse?id=${saveStatus.id} */} {/* add link to <ConditionalView cond={done}> /browse?id=${saveStatus.id} */}
</div> </div>
</div>
) )
} }

View File

@ -1,3 +1,5 @@
//TODO: controllable rate limits
class AuthService { class AuthService {
private API_BASE = '/api/auth' private API_BASE = '/api/auth'

View File

@ -22,6 +22,7 @@ export class SaveParserBackendService {
return '' return ''
} }
//TODO: save size limit 30 mb
async uploadSave(game: string, file: File): Promise<UploadSaveResponse> { async uploadSave(game: string, file: File): Promise<UploadSaveResponse> {
const url = `${this.API_BASE}/uploadSave?game=${encodeURIComponent(game)}` const url = `${this.API_BASE}/uploadSave?game=${encodeURIComponent(game)}`
const response = await fetch(url, { const response = await fetch(url, {