Skip to content

Commit c7d3183

Browse files
authored
Fix: GitHub proxy not displaying correctly in WebUI (#5438)
* fix(dashboard): preserve custom GitHub proxy setting on reload * fix(dashboard): keep github proxy selection persisted in settings
1 parent bcdbc15 commit c7d3183

1 file changed

Lines changed: 47 additions & 17 deletions

File tree

dashboard/src/components/shared/ProxySelector.vue

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<v-expand-transition>
1616
<div v-if="radioValue === '1'" style="margin-left: 16px;">
1717
<v-radio-group v-model="githubProxyRadioControl" class="mt-2" hide-details="true">
18-
<v-radio color="success" v-for="(proxy, idx) in githubProxies" :key="proxy" :value="idx">
18+
<v-radio color="success" v-for="(proxy, idx) in githubProxies" :key="proxy" :value="String(idx)">
1919
<template v-slot:label>
2020
<div class="d-flex align-center">
2121
<span class="mr-2">{{ proxy }}</span>
@@ -37,7 +37,7 @@
3737
</template>
3838
</v-radio>
3939
<v-radio color="primary" value="-1" :label="tm('network.proxySelector.custom')">
40-
<template v-slot:label v-if="githubProxyRadioControl === '-1'">
40+
<template v-slot:label v-if="String(githubProxyRadioControl) === '-1'">
4141
<v-text-field density="compact" v-model="selectedGitHubProxy" variant="outlined"
4242
style="width: 100vw;" :placeholder="tm('network.proxySelector.custom')" hide-details="true">
4343
</v-text-field>
@@ -72,9 +72,21 @@ export default {
7272
loadingTestingConnection: false,
7373
testingProxies: {},
7474
proxyStatus: {},
75+
initializing: true,
7576
}
7677
},
7778
methods: {
79+
getProxyByControl(control) {
80+
const normalizedControl = String(control);
81+
if (normalizedControl === "-1") {
82+
return "";
83+
}
84+
const index = Number.parseInt(normalizedControl, 10);
85+
if (Number.isNaN(index)) {
86+
return "";
87+
}
88+
return this.githubProxies[index] || "";
89+
},
7890
async testSingleProxy(idx) {
7991
this.testingProxies[idx] = true;
8092
@@ -118,42 +130,60 @@ export default {
118130
},
119131
},
120132
mounted() {
121-
this.selectedGitHubProxy = localStorage.getItem('selectedGitHubProxy') || "";
122-
this.radioValue = localStorage.getItem('githubProxyRadioValue') || "0";
123-
this.githubProxyRadioControl = localStorage.getItem('githubProxyRadioControl') || "0";
124-
if (this.radioValue === "1") {
125-
if (this.githubProxyRadioControl !== "-1") {
126-
this.selectedGitHubProxy = this.githubProxies[this.githubProxyRadioControl] || "";
133+
this.initializing = true;
134+
135+
const savedProxy = localStorage.getItem('selectedGitHubProxy') || "";
136+
const savedRadio = localStorage.getItem('githubProxyRadioValue') || "0";
137+
const savedControl = String(localStorage.getItem('githubProxyRadioControl') || "0");
138+
139+
this.radioValue = savedRadio;
140+
this.githubProxyRadioControl = savedControl;
141+
142+
if (savedRadio === "1") {
143+
if (savedControl !== "-1") {
144+
this.selectedGitHubProxy = this.getProxyByControl(savedControl);
145+
} else {
146+
this.selectedGitHubProxy = savedProxy;
127147
}
128148
} else {
129149
this.selectedGitHubProxy = "";
130150
}
151+
152+
this.initializing = false;
131153
},
132154
watch: {
133155
selectedGitHubProxy: function (newVal, oldVal) {
156+
if (this.initializing) {
157+
return;
158+
}
134159
if (!newVal) {
135160
newVal = ""
136161
}
137162
localStorage.setItem('selectedGitHubProxy', newVal);
138163
},
139164
radioValue: function (newVal) {
165+
if (this.initializing) {
166+
return;
167+
}
140168
localStorage.setItem('githubProxyRadioValue', newVal);
141-
if (newVal === "0") {
169+
if (String(newVal) === "0") {
142170
this.selectedGitHubProxy = "";
143-
} else if (this.githubProxyRadioControl !== "-1") {
144-
this.selectedGitHubProxy = this.githubProxies[this.githubProxyRadioControl] || "";
171+
} else if (String(this.githubProxyRadioControl) !== "-1") {
172+
this.selectedGitHubProxy = this.getProxyByControl(this.githubProxyRadioControl);
145173
}
146174
},
147175
githubProxyRadioControl: function (newVal) {
148-
localStorage.setItem('githubProxyRadioControl', newVal);
149-
if (this.radioValue !== "1") {
150-
this.selectedGitHubProxy = "";
176+
if (this.initializing) {
151177
return;
152178
}
153-
if (newVal !== "-1") {
154-
this.selectedGitHubProxy = this.githubProxies[newVal] || "";
155-
} else {
179+
const normalizedVal = String(newVal);
180+
localStorage.setItem('githubProxyRadioControl', normalizedVal);
181+
if (String(this.radioValue) !== "1") {
156182
this.selectedGitHubProxy = "";
183+
return;
184+
}
185+
if (normalizedVal !== "-1") {
186+
this.selectedGitHubProxy = this.getProxyByControl(normalizedVal);
157187
}
158188
}
159189
}

0 commit comments

Comments
 (0)