-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from rossbulat/rb-workspace-tab
feat: add workspace tab
- Loading branch information
Showing
10 changed files
with
271 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 @rossbulat/console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { AnyJson } from '@w3ux/utils/types'; | ||
|
||
// The supported localStorage keys for import and export. | ||
// TODO: Reformat local pageSection keys to host in one `pageSections` key. | ||
const SUPPORTED_WORKSPACE_LOCAL_STORAGE_KEYS = [ | ||
'activeTabs', | ||
'activeTabId', | ||
'activeTabIndex', | ||
'customNodeUrls', | ||
'searchTerms', | ||
'appliedTags', | ||
]; | ||
|
||
// Exporting workspace settings. | ||
export const exportWorkspace = () => { | ||
// Fetch all keys from localStorage | ||
const storageKeys = SUPPORTED_WORKSPACE_LOCAL_STORAGE_KEYS; | ||
const exportData = storageKeys.reduce( | ||
(acc: Record<string, AnyJson>, key: string) => { | ||
try { | ||
const data = localStorage.getItem(key); | ||
// Add local storage item if not falsy. | ||
if (data) { | ||
acc[key] = JSON.parse(data); | ||
} | ||
return acc; | ||
} catch (e) { | ||
// Continue accumulating on error. | ||
return acc; | ||
} | ||
}, | ||
{} | ||
); | ||
|
||
try { | ||
// Convert to JSON and create a data URI to download the file. | ||
const dataStr = JSON.stringify(exportData, undefined); | ||
const dataUri = | ||
'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr); | ||
|
||
const exportFileDefaultName = 'workspace-settings.json'; | ||
|
||
const linkElement = document.createElement('a'); | ||
linkElement.setAttribute('href', dataUri); | ||
linkElement.setAttribute('download', exportFileDefaultName); | ||
linkElement.click(); | ||
linkElement.remove(); | ||
|
||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2024 @rossbulat/console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import { SettingsHeaderWrapper } from 'library/Settings/Wrappers'; | ||
import { | ||
SettingsSubmitWrapper, | ||
SettingsToggleWrapper, | ||
} from '../TabSettings/Wrappers'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { | ||
faDownload, | ||
faFileImport, | ||
faTriangleExclamation, | ||
} from '@fortawesome/free-solid-svg-icons'; | ||
import { useMenu } from 'contexts/Menu'; | ||
import { InDevelopment } from 'library/HelpMenu/InDevelopment'; | ||
import { exportWorkspace } from './Utils'; | ||
import { NotificationsController } from 'controllers/NotificationsController'; | ||
|
||
export const WorkspaceSettings = () => { | ||
const { openMenu } = useMenu(); | ||
|
||
return ( | ||
<> | ||
<SettingsHeaderWrapper> | ||
<h2>Workspace Settings</h2> | ||
</SettingsHeaderWrapper> | ||
|
||
<SettingsToggleWrapper> | ||
<div className="text"> | ||
<h4>Export Workspace</h4> | ||
<h3> | ||
Back up your current workspace state. Exports your tabs, tags, chain | ||
search settings. | ||
</h3> | ||
</div> | ||
</SettingsToggleWrapper> | ||
|
||
<SettingsSubmitWrapper> | ||
<div className="buttons"> | ||
<button | ||
onClick={() => { | ||
if (!exportWorkspace()) { | ||
NotificationsController.emit({ | ||
title: 'Export Failed', | ||
subtitle: 'There was an issue exporting your workspace.', | ||
}); | ||
} | ||
}} | ||
> | ||
<FontAwesomeIcon icon={faDownload} /> | ||
Export Workspace | ||
</button> | ||
</div> | ||
</SettingsSubmitWrapper> | ||
|
||
<SettingsToggleWrapper> | ||
<div className="text"> | ||
<h4>Import Workspace</h4> | ||
<h3>Import a workspace configuration.</h3> | ||
<h3 className="inline danger"> | ||
<FontAwesomeIcon icon={faTriangleExclamation} /> | ||
Importing a workspace will replace your current workspace - | ||
all current state, including your current tabs and custom tag | ||
settings, will be lost. Export your workspace first if you wish to | ||
restore it later. | ||
</h3> | ||
</div> | ||
</SettingsToggleWrapper> | ||
|
||
<SettingsSubmitWrapper> | ||
<div className="buttons"> | ||
<button | ||
onClick={(ev) => openMenu(ev, <InDevelopment />, { size: 'large' })} | ||
> | ||
<FontAwesomeIcon icon={faFileImport} /> | ||
Import Workspace | ||
</button> | ||
</div> | ||
</SettingsSubmitWrapper> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.