]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/alttp-seeds/BaseRomButton.js
tracker medallion controler
[alttp.git] / resources / js / components / alttp-seeds / BaseRomButton.js
1 import React from 'react';
2 import { Button } from 'react-bootstrap';
3 import { withTranslation } from 'react-i18next';
4
5 import i18n from '../../i18n';
6
7 import { useAlttpBaseRom } from '../../helpers/AlttpBaseRomContext';
8
9 const BaseRomButton = () => {
10         const { rom, setRom } = useAlttpBaseRom();
11
12         const handleFile = React.useCallback(async e => {
13                 if (e.target.files.length != 1) {
14                         setRom(null);
15                 } else {
16                         const buf = await e.target.files[0].arrayBuffer();
17                         setRom(buf);
18                 }
19         }, [setRom]);
20
21         if (rom) return null;
22
23         return <span>
24                 <input
25                         accept=".sfc"
26                         className="d-none"
27                         id="alttp.baseRom"
28                         onChange={handleFile}
29                         type="file"
30                 />
31                 <label htmlFor="alttp.baseRom">
32                         <Button as="span" variant="primary">
33                                 {i18n.t('alttp.setBaseRom')}
34                         </Button>
35                 </label>
36         </span>;
37 };
38
39 export default withTranslation()(BaseRomButton);