Skip to content

Commit

Permalink
Allow to edit a WiFi connection
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jun 25, 2024
1 parent fcb312a commit ad385d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
24 changes: 11 additions & 13 deletions web/src/components/network/NetworkPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const NoWiredConnections = () => {
*/
export default function NetworkPage() {
const { network: client } = useInstallerClient();
const { connections: initialConnections, settings } = useLoaderData();
const { connections: initialConnections, devices: initialDevices, settings } = useLoaderData();
const [connections, setConnections] = useState(initialConnections);
const [devices, setDevices] = useState(undefined);
const [devices, setDevices] = useState(initialDevices);

useEffect(() => {
return client.onNetworkChange(({ type, payload }) => {
Expand All @@ -69,6 +69,7 @@ export default function NetworkPage() {
const newDevices = devs.filter((d) => d.name !== name);
return [...newDevices, client.fromApiDevice(data)];
});

break;
}

Expand All @@ -81,12 +82,6 @@ export default function NetworkPage() {
});
}, [client, devices]);

useEffect(() => {
if (devices !== undefined) return;

client.devices().then(setDevices);
}, [client, devices]);

const connectionDevice = ({ id }) => devices?.find(({ connection }) => id === connection);
const connectionAddresses = (connection) => {
const device = connectionDevice(connection);
Expand All @@ -106,17 +101,21 @@ export default function NetworkPage() {
if (!wifiAvailable) return;

return (
<ButtonLink isPrimary={activeConnection} to="wifis">
{activeConnection ? _("Change") : _("Connect")}
</ButtonLink>
<Split hasGutter>
<ButtonLink isPrimary to="wifis">
{_("Change")}
</ButtonLink>
</Split>
);
};

const DisconnectionButton = () => {
if (!wifiAvailable || !activeConnection) return;

return (
<Button variant="secondary">{_("Disconnect")}</Button>
<ButtonLink onClick={async () => await client.disconnect(activeConnection)}>
{_("Disconnect")}
</ButtonLink>
);
};

Expand All @@ -126,7 +125,6 @@ export default function NetworkPage() {
actions={
<Split hasGutter>
<ConnectionButton />
<DisconnectionButton />
</Split>
}
>
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/network/WifiNetworksListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const WifiDrawerPanelBody = ({ network, onCancel }) => {
<ButtonLink onClick={async () => await client.network.connectTo(network.settings)}>
{_("Connect")}
</ButtonLink>
<ButtonLink to={`/network/connections/${network.settings.id}/edit`}>
{_("Edit")}
</ButtonLink>
<Button variant="secondary" isDanger onClick={async () => await client.network.deleteConnection(network.settings.id)}>
{_("Forget")}
</Button>
Expand All @@ -101,6 +104,9 @@ const WifiDrawerPanelBody = ({ network, onCancel }) => {
<ButtonLink onClick={async () => await client.network.disconnect(network.settings)}>
{_("Disconnect")}
</ButtonLink>
<ButtonLink to={`/network/connections/${network.settings.id}/edit`}>
{_("Edit")}
</ButtonLink>
<Button variant="secondary" isDanger onClick={async () => await client.network.deleteConnection(network.settings.id)}>
{_("Forget")}
</Button>
Expand Down
4 changes: 1 addition & 3 deletions web/src/components/network/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ const client = await createDefaultClient();

const loaders = {
all: async () => {
const connections = await client.network.connections();
const devices = await client.network.devices();
const connections = await client.network.connections();
const settings = await client.network.settings();
console.log("loaders.all", connections, devices, settings);
return { connections, devices, settings };
},
connection: async ({ params }) => {
Expand All @@ -45,7 +44,6 @@ const loaders = {
},
wifis: async () => {
const connections = await client.network.connections();
console.log("Obtaining devices");
const devices = await client.network.devices();
const accessPoints = await client.network.accessPoints();
const networks = await client.network.loadNetworks(devices, connections, accessPoints);
Expand Down

0 comments on commit ad385d0

Please sign in to comment.