From d34b2a7088f09325e9727f0e9b7b77779741865c Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:27:26 -0700 Subject: [PATCH] Add QR codes to the ATAK map sources, share one QR component (#1034) 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 --- app/src/components/DonatePage.js | 29 +++----------- app/src/components/MapAtak.js | 15 +++++-- app/src/components/MapAtak.test.js | 17 ++++++++ app/src/components/QRCode.js | 37 ++++++++++++++++++ app/src/components/QRCode.test.js | 39 +++++++++++++++++++ app/src/components/Share.js | 8 +--- app/src/components/admin/ControllerPage.js | 21 +--------- .../calculators/QRCodeCalculator.js | 25 +++--------- 8 files changed, 118 insertions(+), 73 deletions(-) create mode 100644 app/src/components/QRCode.js create mode 100644 app/src/components/QRCode.test.js diff --git a/app/src/components/DonatePage.js b/app/src/components/DonatePage.js index 454ee6aa..f4b99083 100644 --- a/app/src/components/DonatePage.js +++ b/app/src/components/DonatePage.js @@ -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 <> - setOpen(true)}/> - setOpen(false)} - onOpen={() => setOpen(true)} - > - {header} - - {/* `media`: the white field a scanner needs is filtered as a unit by night mode, - rather than sitting on screen as a lit panel. */} -
- -
-
-
- + return ; } function CoinRow({header, qrCodeValue, address, buttonColor}) { diff --git a/app/src/components/MapAtak.js b/app/src/components/MapAtak.js index a46dceeb..daced1ef 100644 --- a/app/src/components/MapAtak.js +++ b/app/src/components/MapAtak.js @@ -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}) { {url} - navigator.clipboard.writeText(url)}/> + + navigator.clipboard.writeText(url)}/> + +

{url}

+
+
; } @@ -104,8 +111,8 @@ function HowTo() {
    -
  1. On the phone, open a map source address above in its browser; it downloads a small - file. +
  2. On the phone, open a map source address above in its browser (or scan its QR code); + it downloads a small file.
  3. Open that file with ATAK or iTAK (or import it with the app's import tool).
  4. Choose WROLPi Map (or WROLPi Map (HTTPS)) in the app's list of maps.
  5. diff --git a/app/src/components/MapAtak.test.js b/app/src/components/MapAtak.test.js index 2edce416..865e4ecc 100644 --- a/app/src/components/MapAtak.test.js +++ b/app/src/components/MapAtak.test.js @@ -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(); + 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(); diff --git a/app/src/components/QRCode.js b/app/src/components/QRCode.js new file mode 100644 index 00000000..5a2bbf57 --- /dev/null +++ b/app/src/components/QRCode.js @@ -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
    + +
    ; +} + +// A modal which shows a QR code of `value`, then `children` (if any) beneath it. +export function QRCodeModal({open, onClose, header, value, children}) { + return + {header && {header}} + + + {children} + + ; +} + +// 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 <> + setOpen(true)}/> + setOpen(false)} header={header ?? label} value={value}> + {children} + + ; +} diff --git a/app/src/components/QRCode.test.js b/app/src/components/QRCode.test.js new file mode 100644 index 00000000..81327e30 --- /dev/null +++ b/app/src/components/QRCode.test.js @@ -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(); + // 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( +

    Beneath the code

    +
    ); + 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(); + fireEvent.click(screen.getByRole('button', {name: 'Join the hotspot'})); + const dialog = await screen.findByRole('dialog'); + expect(within(dialog).getByText('Join the hotspot')).toBeInTheDocument(); + }); +}); diff --git a/app/src/components/Share.js b/app/src/components/Share.js index f04bf21f..18860b61 100644 --- a/app/src/components/Share.js +++ b/app/src/components/Share.js @@ -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}) => { Share this page
    Another user can scan this QR code to view this page
    - {/* `media`: filtered as a unit by night mode; see DonatePage. */} -
    - -
    +
    diff --git a/app/src/components/admin/ControllerPage.js b/app/src/components/admin/ControllerPage.js index ef29cd29..9edaa344 100644 --- a/app/src/components/admin/ControllerPage.js +++ b/app/src/components/admin/ControllerPage.js @@ -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 - setQrOpen(true)} - /> - setQrOpen(false)} closeIcon> - Scan this code to join the hotspot - - {/* `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. */} -
    - -
    -
    -
    + ; } diff --git a/app/src/components/calculators/QRCodeCalculator.js b/app/src/components/calculators/QRCodeCalculator.js index 6446642a..6b2cda13 100644 --- a/app/src/components/calculators/QRCodeCalculator.js +++ b/app/src/components/calculators/QRCodeCalculator.js @@ -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() {
    QR Code Calculator
    setValue(e.target.value)} placeholder='Enter link, etc.'/> -
    - -
    +
    -
    - -
    +
    }