Also close eventsource on unmounted
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
|
||||
import { ref, onUnmounted } from 'vue';
|
||||
import { Button } from '@cloudron/pankow';
|
||||
import { prettyDecimalSize } from '@cloudron/pankow/utils';
|
||||
import SystemModel from '../models/SystemModel.js';
|
||||
@@ -127,13 +128,13 @@ function getNextColor() {
|
||||
// });
|
||||
// }
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
const isExpanded = ref(false);
|
||||
const percent = ref(0);
|
||||
const contents = ref([]);
|
||||
const speed = ref(-1);
|
||||
|
||||
let eventSource = null;
|
||||
|
||||
async function onExpand() {
|
||||
if (isExpanded.value) return;
|
||||
|
||||
@@ -141,9 +142,11 @@ async function onExpand() {
|
||||
|
||||
isExpanded.value = true;
|
||||
|
||||
const [error, eventSource] = await systemModel.filesystemUsage(props.filesystem.filesystem);
|
||||
const [error, result] = await systemModel.filesystemUsage(props.filesystem.filesystem);
|
||||
if (error) return console.error(error);
|
||||
|
||||
eventSource = result;
|
||||
|
||||
eventSource.addEventListener('message', function (message) {
|
||||
const payload = JSON.parse(message.data);
|
||||
|
||||
@@ -168,6 +171,11 @@ async function onExpand() {
|
||||
});
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (eventSource) eventSource.close();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user