From 742b68453a0fac32389c61f17340d40bddd5d9ea Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 22 Mar 2021 18:31:33 +0100 Subject: [PATCH] favorite modal --- .../src/appobj/FavoriteFileAppObject.svelte | 3 +- packages/web/src/forms/FormValues.svelte | 7 + packages/web/src/modals/FavoriteModal.svelte | 154 ++++++++++++++++++ packages/web/src/stores.ts | 7 + packages/web/src/widgets/TabsPanel.svelte | 19 ++- 5 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 packages/web/src/forms/FormValues.svelte create mode 100644 packages/web/src/modals/FavoriteModal.svelte diff --git a/packages/web/src/appobj/FavoriteFileAppObject.svelte b/packages/web/src/appobj/FavoriteFileAppObject.svelte index 41756718..9c431432 100644 --- a/packages/web/src/appobj/FavoriteFileAppObject.svelte +++ b/packages/web/src/appobj/FavoriteFileAppObject.svelte @@ -36,13 +36,14 @@ import { showModal } from '../modals/modalTools'; import ConfirmModal from '../modals/ConfirmModal.svelte'; import getElectron from '../utility/getElectron'; + import FavoriteModal from '../modals/FavoriteModal.svelte'; export let data; const electron = getElectron(); const editFavorite = () => { - // showModal(modalState => ); + showModal(FavoriteModal, { editingData: data }); }; const editFavoriteJson = async () => { diff --git a/packages/web/src/forms/FormValues.svelte b/packages/web/src/forms/FormValues.svelte new file mode 100644 index 00000000..c43cc2cd --- /dev/null +++ b/packages/web/src/forms/FormValues.svelte @@ -0,0 +1,7 @@ + + + diff --git a/packages/web/src/modals/FavoriteModal.svelte b/packages/web/src/modals/FavoriteModal.svelte new file mode 100644 index 00000000..98503ab4 --- /dev/null +++ b/packages/web/src/modals/FavoriteModal.svelte @@ -0,0 +1,154 @@ + + + + + {editingData ? 'Edit favorite' : 'Share / add to favorites'} + + + + + + {#if !!savingTab && !electron && canWriteFavorite} + + {/if} + + {#if !values.shareAsLink && canWriteFavorite} + + + {/if} + + {#if !!savingTab && !!savedFile} + + {/if} + + + + {#if !values.shareAsLink && canWriteFavorite} + + {/if} + {#if values.shareAsLink || !canWriteFavorite} + + {/if} + + + + + diff --git a/packages/web/src/stores.ts b/packages/web/src/stores.ts index 6fb35e8b..2fe726ee 100644 --- a/packages/web/src/stores.ts +++ b/packages/web/src/stores.ts @@ -37,6 +37,7 @@ export const visibleCommandPalette = writable(false); export const commands = writable({}); export const currentTheme = writableWithStorage('theme-light', 'currentTheme'); export const activeTabId = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)?.tabid); +export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)); export const visibleToolbar = writableWithStorage(1, 'visibleToolbar'); export const leftPanelWidth = writable(300); @@ -90,3 +91,9 @@ commands.subscribe(value => { } }); export const getCommands = () => commandsValue; + +let activeTabValue = null; +activeTab.subscribe(value => { + activeTabValue = value; +}); +export const getActiveTab = () => activeTabValue; diff --git a/packages/web/src/widgets/TabsPanel.svelte b/packages/web/src/widgets/TabsPanel.svelte index 10fd626d..eb0571f4 100644 --- a/packages/web/src/widgets/TabsPanel.svelte +++ b/packages/web/src/widgets/TabsPanel.svelte @@ -83,6 +83,20 @@ testEnabled: () => getOpenedTabs().filter(x => !x.closedTime).length >= 1, onClick: closeAll, }); + + registerCommand({ + id: 'tabs.share', + category: 'Tabs', + name: 'Share', + icon: 'icon share', + toolbar: true, + testEnabled: () => + getActiveTab()?.tabComponent && + tabs[getActiveTab()?.tabComponent] && + tabs[getActiveTab()?.tabComponent].allowAddToFavorites && + tabs[getActiveTab()?.tabComponent].allowAddToFavorites(getActiveTab()?.props), + onClick: () => showModal(FavoriteModal, { savingTab: getActiveTab() }), + });