Skip to content

Commit

Permalink
feat: update port selection to update the options
Browse files Browse the repository at this point in the history
  • Loading branch information
chmelevskij committed Apr 27, 2024
1 parent 4a069a9 commit 839c2ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/components/eventBus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Vue from "vue";
export const EventBus = new Vue();
2 changes: 1 addition & 1 deletion src/components/port-picker/PortPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
},
data() {
return {
port: 'virtual',
port: 'manual',
};
},
};
Expand Down
28 changes: 23 additions & 5 deletions src/components/port-picker/PortsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
@value="value"
@input="$emit('input', $event.target.value)"
>
<option value="virtual">
{{ $t("portsSelectVirtual") }}
</option>
<option value="manual">
{{ $t("portsSelectManual") }}
</option>
<option
v-if="showVirtual"
value="virtual"
>
{{ $t("portsSelectVirtual") }}
</option>
</select>
</div>
<div id="auto-connect-and-baud">
Expand All @@ -43,16 +46,20 @@
</template>

<script>
import { get as getConfig } from '../../js/ConfigStorage';
import { EventBus } from '../eventBus';
export default {
props: {
value: {
type: String,
// TODO: this should be loaded from config
default: 'virtual',
default: 'manual',
},
},
data() {
return {
showVirtual: false,
selectedBaudRate: "115200",
baudRates: [
{ value: "1000000", label: "1000000" },
Expand All @@ -71,6 +78,17 @@ export default {
],
};
},
mounted() {
EventBus.$on('config-storage:set', this.setShowVirtual);
},
destroyed() {
EventBus.$off('config-storage:set', this.setShowVirtual);
},
methods: {
setShowVirtual() {
this.showVirtual = getConfig('showVirtualMode').showVirtualMode;
},
},
};
</script>
<style scoped>
Expand Down
3 changes: 3 additions & 0 deletions src/js/ConfigStorage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EventBus } from "../components/eventBus";

/**
* Gets one or more items from localStorage
* @param {string | string[]} key string or array of strings
Expand Down Expand Up @@ -43,6 +45,7 @@ export function set(input) {
tmpObj[element] = input[element];
try {
localStorage.setItem(element, JSON.stringify(tmpObj));
EventBus.$emit(`config-storage:set`, 'element');
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit 839c2ff

Please sign in to comment.