tab status bar improved

This commit is contained in:
Jan Prochazka
2021-11-21 12:39:52 +01:00
parent a5bc66eb27
commit 6a606bc733
4 changed files with 56 additions and 20 deletions

View File

@@ -1,15 +1,34 @@
<script lang="ts" context="module">
const statusBarTabInfo = writable({});
export function updateStatuBarInfo(tabid, info) {
statusBarTabInfo.update(x => ({
...x,
[tabid]: info,
}));
// export function updateStatuBarInfo(tabid, info) {
// statusBarTabInfo.update(x => ({
// ...x,
// [tabid]: info,
// }));
// }
export function updateStatuBarInfoItem(tabid, key, item) {
statusBarTabInfo.update(tabs => {
const items = tabs[tabid] || [];
let newItems;
if (item == null) {
newItems = items.filter(x => x.key != key);
} else if (items.find(x => x.key == key)) {
newItems = items.map(x => (x.key == key ? { ...item, key } : x));
} else {
newItems = [...items, { ...item, key }];
}
return {
...tabs,
[tabid]: newItems,
};
});
}
</script>
<script lang="ts">
import _ from 'lodash';
import { writable } from 'svelte/store';
import moment from 'moment';

View File

@@ -0,0 +1,16 @@
<script lang="ts">
import { getContext, onDestroy, onMount } from 'svelte';
import uuidv1 from 'uuid/v1';
import { updateStatuBarInfoItem } from './StatusBar.svelte';
export let text;
const key = uuidv1();
const tabid = getContext('tabid');
onMount(() => {
updateStatuBarInfoItem(tabid, key, { text });
});
onDestroy(() => updateStatuBarInfoItem(tabid, key, null));
</script>