hardlounge/client/components/Windows/NetworkEdit.vue

68 lines
1.5 KiB
Vue
Raw Permalink Normal View History

2019-02-18 09:18:32 +00:00
<template>
<NetworkForm
v-if="networkData"
:handle-submit="handleSubmit"
:defaults="networkData"
:disabled="disabled"
/>
2019-02-18 09:18:32 +00:00
</template>
<script lang="ts">
import {defineComponent, onMounted, ref, watch} from "vue";
import {useRoute} from "vue-router";
import {switchToChannel} from "../../js/router";
2019-11-16 17:24:03 +00:00
import socket from "../../js/socket";
import {useStore} from "../../js/store";
import NetworkForm, {NetworkFormDefaults} from "../NetworkForm.vue";
2019-02-18 09:18:32 +00:00
export default defineComponent({
2019-02-18 09:18:32 +00:00
name: "NetworkEdit",
components: {
NetworkForm,
2019-02-18 09:18:32 +00:00
},
setup() {
const route = useRoute();
const store = useStore();
const disabled = ref(false);
const networkData = ref<NetworkFormDefaults | null>(null);
const setNetworkData = () => {
socket.emit("network:get", String(route.params.uuid || ""));
networkData.value = store.getters.findNetwork(String(route.params.uuid || ""));
2019-02-18 09:18:32 +00:00
};
const handleSubmit = (data: {uuid: string; name: string}) => {
disabled.value = true;
socket.emit("network:edit", data);
2019-02-18 09:18:32 +00:00
// TODO: move networks to vuex and update state when the network info comes in
const network = store.getters.findNetwork(data.uuid);
2019-11-07 09:29:04 +00:00
if (network) {
network.name = network.channels[0].name = data.name;
switchToChannel(network.channels[0]);
}
};
watch(
() => route.params.uuid,
(newValue) => {
setNetworkData();
}
);
onMounted(() => {
setNetworkData();
});
return {
disabled,
networkData,
handleSubmit,
};
2019-02-18 09:18:32 +00:00
},
});
2019-02-18 09:18:32 +00:00
</script>