Add QR codes to the ATAK map sources, share one QR component (#1034)
Some checks are pending
Backend Tests / api-tests (core) (push) Waiting to run
Backend Tests / api-tests (files) (push) Waiting to run
Backend Tests / api-tests (media) (push) Waiting to run
Backend Tests / api-tests (rest) (push) Waiting to run
Backend Tests / api-contract-tests (push) Waiting to run
Backend Tests / api-migrations-and-start (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Cypress Tests / cypress-component-tests (push) Waiting to run
Cypress Tests / cypress-e2e-tests (push) Waiting to run
Dead Code / vulture (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

The ATAK tab's HTTP and HTTPS map source rows get a QR code button beside
the copy button, so a phone can scan the address and download the map
source file.

QRCodeImage, QRCodeModal, and QRCodeButton (components/QRCode.js) replace
the five copies of the night-mode-safe white field + modal used by Share,
Donate, the hotspot settings, and the QR code calculator.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-28 16:27:26 -07:00 • committed by GitHub
parent 2c3300b8b0
commit d34b2a7088
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 118 additions and 73 deletions

View file

@ -1,7 +1,7 @@
import React, {useState} from "react";
import React from "react";
import {PageContainer, useTitle} from "./Common";
import {Button, Header, IconButton, Modal, Panel, Table} from "./ui";
import QRCode from "react-qr-code";
import {Button, Header, Panel, Table} from "./ui";
import {QRCodeButton} from "./QRCode";
const bitcoinAddress = '1mi1ddLSd6LmkuwJd1ttZsKuED724vYjS';
const bitcoinContent = `bitcoin:${bitcoinAddress}`;
@ -13,27 +13,8 @@ const moneroAddress = '87jv2NpGb5sbUwk7zYYwEY5RAoh1jRfTo4d1BAewVdJJFKg2bDF2UXtLf
const moneroContent = `monero:${moneroAddress};`
function CoinQRButton({qrCodeValue, header, buttonColor}) {
const [open, setOpen] = useState(false);
return <>
<IconButton icon='qrcode' label={`Show ${header} QR code`} color={buttonColor}
onClick={() => setOpen(true)}/>
<Modal size='small' closeIcon
open={open}
onClose={() => setOpen(false)}
onOpen={() => setOpen(true)}
>
<Modal.Header>{header}</Modal.Header>
<Modal.Content>
{/* `media`: the white field a scanner needs is filtered as a unit by night mode,
rather than sitting on screen as a lit panel. */}
<div className='media'
style={{backgroundColor: '#FFFFFF', display: 'inline-block', padding: '1em'}}>
<QRCode value={qrCodeValue} size={300}/>
</div>
</Modal.Content>
</Modal>
</>
return <QRCodeButton value={qrCodeValue} label={`Show ${header} QR code`} header={header}
color={buttonColor}/>;
}
function CoinRow({header, qrCodeValue, address, buttonColor}) {

View file

@ -3,6 +3,7 @@
import React, {useCallback, useEffect, useRef, useState} from "react";
import {APIButton, ErrorMessage, humanFileSize, InfoMessage} from "./Common";
import {Group, Header, Panel, Table} from "./ui";
import {QRCodeButton} from "./QRCode";
// How often the status is asked for while the tab is open.
const STATUS_INTERVAL_MS = 5000;
@ -77,8 +78,14 @@ function MapSourceRow({label, name, url, note}) {
</Table.Cell>
<Table.Cell style={{wordBreak: 'break-all'}}><a href={url}>{url}</a></Table.Cell>
<Table.Cell>
<APIButton icon='copy' aria-label={`Copy ${label} map source address`}
onClick={() => navigator.clipboard.writeText(url)}/>
<Group gap='xs' wrap='nowrap'>
<APIButton icon='copy' aria-label={`Copy ${label} map source address`}
onClick={() => navigator.clipboard.writeText(url)}/>
<QRCodeButton value={url} color='violet' label={`Show ${label} map source QR code`}
header={`Scan with the phone to download the ${label} map source`}>
<p style={{wordBreak: 'break-all'}}>{url}</p>
</QRCodeButton>
</Group>
</Table.Cell>
</Table.Row>;
}
@ -104,8 +111,8 @@ function HowTo() {
</Table.Body>
</Table>
<ol>
<li>On the phone, open a map source address above in its browser; it downloads a small
file.
<li>On the phone, open a map source address above in its browser (or scan its QR code);
it downloads a small file.
</li>
<li>Open that file with ATAK or iTAK (or import it with the app's import tool).</li>
<li>Choose <b>WROLPi Map</b> (or <b>WROLPi Map (HTTPS)</b>) in the app's list of maps.</li>

View file

@ -50,6 +50,23 @@ describe('MapAtak', () => {
expect(screen.getByText('30s ago')).toBeInTheDocument();
});
it('shows a QR code of each map source address for the phone to scan', async () => {
global.fetch = mockFetch(STATUS);
renderWithProviders(<MapAtak/>);
await screen.findByText('31.5 per second (last minute)');
for (const [label, url] of [['HTTP', httpMapSourceUrl()], ['HTTPS', httpsMapSourceUrl()]]) {
fireEvent.click(screen.getByRole('button', {name: `Show ${label} map source QR code`}));
const dialog = await screen.findByRole('dialog');
// react-qr-code renders an svg titled with its value.
expect(within(dialog).getByTitle(url)).toBeInTheDocument();
expect(within(dialog).getByText(`Scan with the phone to download the ${label} map source`))
.toBeInTheDocument();
fireEvent.keyDown(dialog, {key: 'Escape'});
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
}
});
it('says when the tile service is not running', async () => {
global.fetch = jest.fn(() => Promise.reject(new Error('connection refused')));
renderWithProviders(<MapAtak/>);

View file

@ -0,0 +1,37 @@
// QR codes for a phone to scan: the code itself, a modal which shows one, and a button which opens it.
import React, {useState} from "react";
import QRCode from "react-qr-code";
import {IconButton, Modal} from "./ui";
// A scannable QR code of `value`. `style` adds to (or replaces) the white field around it.
export function QRCodeImage({value, size = 300, style}) {
// `media`: a QR code needs real black-on-white contrast to scan, so its white field is filtered
// as a unit by night mode rather than sitting on screen as a lit panel.
return <div className='media'
style={{display: 'inline-block', backgroundColor: '#ffffff', padding: '1em', ...style}}>
<QRCode value={value} size={size} title={value}/>
</div>;
}
// A modal which shows a QR code of `value`, then `children` (if any) beneath it.
export function QRCodeModal({open, onClose, header, value, children}) {
return <Modal size='small' open={open} onClose={onClose} closeIcon>
{header && <Modal.Header>{header}</Modal.Header>}
<Modal.Content>
<QRCodeImage value={value}/>
{children}
</Modal.Content>
</Modal>;
}
// A QR code icon button which opens a QRCodeModal of `value`. `label` names the button; the modal's
// header defaults to it.
export function QRCodeButton({value, label, header, color, size, children}) {
const [open, setOpen] = useState(false);
return <>
<IconButton icon='qrcode' label={label} color={color} size={size} onClick={() => setOpen(true)}/>
<QRCodeModal open={open} onClose={() => setOpen(false)} header={header ?? label} value={value}>
{children}
</QRCodeModal>
</>;
}

View file

@ -0,0 +1,39 @@
import React from 'react';
import {fireEvent, screen, waitFor, within} from '@testing-library/react';
import {renderWithProviders} from '../test-utils';
import {QRCodeButton, QRCodeImage} from './QRCode';
describe('QRCode', () => {
it('draws the code on a white field which night mode filters as a unit', () => {
renderWithProviders(<QRCodeImage value='https://example.com/a' size={128}/>);
// react-qr-code titles its svg with the value.
const svg = screen.getByTitle('https://example.com/a').closest('svg');
expect(svg).toHaveAttribute('height', '128');
const field = svg.parentElement;
expect(field).toHaveClass('media');
expect(field).toHaveStyle({backgroundColor: '#ffffff'});
});
it('opens a modal of the code from its button, then closes it', async () => {
renderWithProviders(<QRCodeButton value='WIFI:S:x;;' label='Show the code' header='Scan this'>
<p>Beneath the code</p>
</QRCodeButton>);
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', {name: 'Show the code'}));
const dialog = await screen.findByRole('dialog');
expect(within(dialog).getByText('Scan this')).toBeInTheDocument();
expect(within(dialog).getByTitle('WIFI:S:x;;')).toBeInTheDocument();
expect(within(dialog).getByText('Beneath the code')).toBeInTheDocument();
fireEvent.keyDown(dialog, {key: 'Escape'});
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
});
it('titles the modal with the button label when no header is given', async () => {
renderWithProviders(<QRCodeButton value='x' label='Join the hotspot'/>);
fireEvent.click(screen.getByRole('button', {name: 'Join the hotspot'}));
const dialog = await screen.findByRole('dialog');
expect(within(dialog).getByText('Join the hotspot')).toBeInTheDocument();
});
});

View file

@ -1,6 +1,6 @@
import React from "react";
import {Button, Header, Icon, IconButton, Modal} from "./ui";
import QRCode from "react-qr-code";
import {QRCodeImage} from "./QRCode";
import {sendNotification} from "../api";
export const ShareEveryoneButton = ({url, size, onClick}) => {
@ -49,11 +49,7 @@ export const ShareButton = ({asIcon = false}) => {
<Modal.Header>Share this page</Modal.Header>
<Modal.Content>
<Header as='h4'>Another user can scan this QR code to view this page</Header>
{/* `media`: filtered as a unit by night mode; see DonatePage. */}
<div className='media'
style={{padding: '1em', backgroundColor: '#ffffff', display: "inline-block"}}>
<QRCode value={window.location.href}/>
</div>
<QRCodeImage value={window.location.href} size={256}/>
</Modal.Content>
<Modal.Actions>
<ShareEveryoneButton url={window.location.href} onClick={handleClose}/>

View file

@ -46,7 +46,7 @@ import {
unmountDisk,
updateHotspotSettings,
} from "../../api/controller";
import QRCode from "react-qr-code";
import {QRCodeButton} from "../QRCode";
import {RestartButton, ShutdownButton} from "./Settings";
import {CONTROLLER_URI} from "../Vars";
import {VpnSection} from "./VpnSection";
@ -1463,7 +1463,6 @@ function HotspotSettingsForm() {
{device: '', ssid: '', password: '', protocol: '', captive_portal: true});
const [loading, setLoading] = React.useState(true);
const [saving, setSaving] = React.useState(false);
const [qrOpen, setQrOpen] = React.useState(false);
const [hotspotStatus, setHotspotStatus] = React.useState(null);
const {on: hotspotOn} = useHotspot();
@ -1642,23 +1641,7 @@ function HotspotSettingsForm() {
loading={saving}
onClick={handleSave}
>Save</Button>
<IconButton
icon='qrcode'
label='Scan this code to join the hotspot'
color='violet'
onClick={() => setQrOpen(true)}
/>
<Modal size='small' open={qrOpen} onClose={() => setQrOpen(false)} closeIcon>
<Modal.Header>Scan this code to join the hotspot</Modal.Header>
<Modal.Content>
{/* `media`: filtered as a unit by night mode; a QR code needs real black-on-white
contrast to scan, so it is exempted the same way DonatePage's and Share's are. */}
<div className='media'
style={{display: 'inline-block', backgroundColor: '#ffffff', padding: '1em'}}>
<QRCode value={qrCodeValue} size={300}/>
</div>
</Modal.Content>
</Modal>
<QRCodeButton value={qrCodeValue} color='violet' label='Scan this code to join the hotspot'/>
</div>
</Panel>;
}

View file

@ -1,5 +1,5 @@
import React from "react";
import QRCode from "react-qr-code";
import {QRCodeImage} from "../QRCode";
import {Header, Stack, TextInput} from "../ui";
import {Media} from "../../contexts/contexts";
@ -10,27 +10,12 @@ export function QRCodeCalculator() {
<Header as='h1'>QR Code Calculator</Header>
<TextInput value={value} onChange={e => setValue(e.target.value)} placeholder='Enter link, etc.'/>
<Media at='mobile'>
<div className='media' style={{
height: "auto",
margin: "0 auto",
width: '332px',
background: 'white',
padding: '16px'
}}>
<QRCode value={value} size={300}/>
</div>
<QRCodeImage value={value} size={300}
style={{display: 'block', margin: '0 auto', width: '332px', padding: '16px'}}/>
</Media>
<Media greaterThanOrEqual='tablet'>
<div className='media' style={{
height: "auto",
margin: "0 auto",
maxWidth: '632px',
width: "100%",
background: 'white',
padding: '16px'
}}>
<QRCode value={value} size={600}/>
</div>
<QRCodeImage value={value} size={600}
style={{display: 'block', margin: '0 auto', maxWidth: '632px', width: '100%', padding: '16px'}}/>
</Media>
</Stack>
}