Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions photon-client/src/components/settings/NetworkingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@
return hostnameRegex.test(v);
};

// When the user hits Enter in the Static IP field, save and redirect
const onStaticIpEnter = (newIp: string) => {
if (!isValidIPv4(newIp)) return;

// Kick off save so backend applies change, then navigate
saveGeneralSettings();

// Give the backend a moment to switch networking, then redirect
// Keep current hash route (e.g., #/settings)
const hash = window.location.hash || "";
const url = `http://${newIp}:5800/${hash}`;
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better here to find out when the backend is actually ready for the redirect, instead of picking an arbitrary delay and hoping it's both enough and not excessively long? maybe we can trigger the redirect on a response from the backend?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how the backend handles a new static IP. If it delete the old one, all you'll see is the HTTP connection drop, but if it doesn't, you might be able to wait for the HTTP response?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might just be better to launch a fetch request and wait for a response.

window.location.href = url;
}, 1000);
};

const settingsHaveChanged = (): boolean => {
const a = useSettingsStore().network;
const b = tempSettingsStruct.value;
Expand Down Expand Up @@ -209,10 +225,11 @@
v-show="!useSettingsStore().network.networkingDisabled"
v-if="tempSettingsStruct.connectionType === NetworkConnectionType.Static"
v-model="tempSettingsStruct.staticIp"
@onEnter="onStaticIpEnter"
:input-cols="12 - 4"

Check warning on line 229 in photon-client/src/components/settings/NetworkingCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

Attribute ":input-cols" should go before "@onEnter"
label="Static IP"

Check warning on line 230 in photon-client/src/components/settings/NetworkingCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

Attribute "label" should go before "@onEnter"
:rules="[(v) => isValidIPv4(v) || 'Invalid IPv4 address']"

Check warning on line 231 in photon-client/src/components/settings/NetworkingCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

Attribute ":rules" should go before "@onEnter"
:disabled="

Check warning on line 232 in photon-client/src/components/settings/NetworkingCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

Attribute ":disabled" should go before "@onEnter"
!tempSettingsStruct.shouldManage ||
!useSettingsStore().network.canManage ||
useSettingsStore().network.networkingDisabled
Expand Down
Loading