From 31b778c56eed76960ff0522ea2125b973ed822d6 Mon Sep 17 00:00:00 2001 From: heapwolf Date: Fri, 29 Mar 2024 23:46:23 +0100 Subject: [PATCH] improve tree and create project --- src/components/editor.js | 9 ++++--- src/components/project.js | 38 ++++++++++++++++++++--------- src/components/properties.js | 14 +++++------ src/components/subscribe.js | 23 ++++++++++++++--- src/css/component-editor.css | 2 +- src/css/theme.css | 2 +- src/css/view-project-summary.css | 39 +++++++++++++++++++++++++++++ src/index.html | 1 + src/index.js | 9 ++++--- src/views/project-summary.js | 42 ++++++++++++++++++++++++++++++++ 10 files changed, 148 insertions(+), 31 deletions(-) create mode 100644 src/css/view-project-summary.css create mode 100644 src/views/project-summary.js diff --git a/src/components/editor.js b/src/components/editor.js index cca6e10..4f27a39 100644 --- a/src/components/editor.js +++ b/src/components/editor.js @@ -335,6 +335,7 @@ class AppEditor extends Tonic { const colors = { background: rgbaToHex(styles.getPropertyValue('--tonic-background').trim()), primary: rgbaToHex(styles.getPropertyValue('--tonic-primary').trim()), + secondary: rgbaToHex(styles.getPropertyValue('--tonic-secondary').trim()), info: rgbaToHex(styles.getPropertyValue('--tonic-info').trim()), dark: rgbaToHex(styles.getPropertyValue('--tonic-dark').trim()), accent: rgbaToHex(styles.getPropertyValue('--tonic-accent').trim()), @@ -354,7 +355,7 @@ class AppEditor extends Tonic { { token: 'keyword', foreground: colors.accent }, { token: 'punctuation', foreground: colors.primary }, - { token: '', foreground: 'D4D4D4', background: '1E1E1E' }, + { token: '', foreground: colors.primary }, { token: 'invalid', foreground: 'f44747' }, { token: 'emphasis', fontStyle: 'italic' }, { token: 'strong', fontStyle: 'bold' }, @@ -363,7 +364,7 @@ class AppEditor extends Tonic { { token: 'variable.predefined', foreground: '4864AA' }, { token: 'variable.parameter', foreground: '9CDCFE' }, { token: 'constant', foreground: '569CD6' }, - { token: 'comment', foreground: colors.info }, + { token: 'comment', foreground: '338c32' }, { token: 'number', foreground: colors.accent }, { token: 'number.hex', foreground: '5BB498' }, { token: 'regexp', foreground: 'B46695' }, @@ -377,8 +378,8 @@ class AppEditor extends Tonic { { token: 'tag', foreground: '569CD6' }, { token: 'meta.scss', foreground: 'A79873' }, { token: 'meta.tag', foreground: 'CE9178' }, - { token: 'metatag', foreground: 'DD6A6F' }, - { token: 'metatag.content.html', foreground: '9CDCFE' }, + { token: 'metatag', foreground: colors.accent }, + { token: 'metatag.content.html', foreground: colors.primary }, { token: 'metatag.html', foreground: '569CD6' }, { token: 'metatag.xml', foreground: '569CD6' }, { token: 'metatag.php', fontStyle: 'bold' }, diff --git a/src/components/project.js b/src/components/project.js index 531b6db..bdc54d1 100644 --- a/src/components/project.js +++ b/src/components/project.js @@ -11,7 +11,7 @@ const NOT_SELECTED = 0 const IS_SELECTED = 1 async function rm (directory) { - const files = await fs.promises.readdir(directory, { withfiletypes: true }) + const files = await fs.promises.readdir(directory, { withFileTypes: true }) for (const file of files) { const filePath = path.join(directory, file.name) @@ -334,6 +334,8 @@ class AppProject extends Tonic { if (!node) this.getNodeFromElement(el.parentElement) if (!node) return + if (node.nonMovable && !node.type === 'project') return + const container = el.querySelector('.label') const input = document.createElement('input') @@ -444,7 +446,11 @@ class AppProject extends Tonic { } if (value === 'delete') { - if (node.isDirectory) { + if (node.type === 'project') { + const app = this.props.parent + await app.db.projects.del(node.id) + await rm(node.id) + } else if (node.isDirectory) { try { await rm(node.id) } catch (err) { @@ -496,10 +502,18 @@ class AppProject extends Tonic { async onSelection (node, isToggle) { if (!isToggle) { + const app = this.props.parent const projectNode = this.getProjectNode(node) + const coImagePreview = document.querySelector('view-image-preview') + const coProjectSummary = document.querySelector('view-project-summary') + const coHome = document.querySelector('view-home') + + coImagePreview.hide() + coProjectSummary.hide() + coHome.hide() // Check if the project has changed, refresh the props component - if (this.state.currentProject !== projectNode.id) { + if (this.state.currentProjectId !== projectNode.id) { this.props.parent.state.currentProject = projectNode this.props.parent.reloadPreviewWindows() @@ -507,15 +521,15 @@ class AppProject extends Tonic { coProperties.loadProjectNode(projectNode) } - this.state.currentProject = projectNode.id - - if (node.isDirectory) return + this.state.currentProjectId = projectNode.id - const coImagePreview = document.querySelector('view-image-preview') - const coHome = document.querySelector('view-home') + if (node.type === 'project') { + await coProjectSummary.reRender() + coProjectSummary.show() + return + } - coImagePreview.hide() - coHome.hide() + if (node.isDirectory) return if (projectNode.id === 'home') { coHome.show() @@ -712,9 +726,11 @@ class AppProject extends Tonic { selected: oldChild?.selected ?? 0, state: oldChild?.state ?? 0, id: project.path, + projectId, label: project.label, - isDirectory: true, + isDirectory: false, nonMovable: true, + type: 'project', icon: 'package', children: [] } diff --git a/src/components/properties.js b/src/components/properties.js index fe99822..2732bc6 100644 --- a/src/components/properties.js +++ b/src/components/properties.js @@ -52,7 +52,7 @@ class AppProperties extends Tonic { const project = document.querySelector('app-project') const config = new Config(app.state.currentProject?.id) - if (event === 'org-name' || event === 'shared-secret') { + if (event === 'org' || event === 'shared-secret') { const app = this.props.parent const config = new Config(app.state.currentProject?.id) if (!config) return @@ -61,8 +61,8 @@ class AppProperties extends Tonic { if (bundleId) bundleId = bundleId.replace(/"/g, '') const { data: dataBundle } = await app.db.projects.get(bundleId) - if (event === 'org-name') { - dataBundle.orgName = el.value + if (event === 'org') { + dataBundle.org = el.value dataBundle.clusterId = await sha256(el.value, { bytes: true }) } @@ -193,7 +193,7 @@ class AppProperties extends Tonic { clusterId, subclusterId, sharedKey, - orgName: 'socket-app-studio', + org: 'union-app-studio', }) await app.db.projects.put(bundleId, project) @@ -323,9 +323,9 @@ class AppProperties extends Tonic { diff --git a/src/components/subscribe.js b/src/components/subscribe.js index 6588ffd..759d4e2 100644 --- a/src/components/subscribe.js +++ b/src/components/subscribe.js @@ -19,6 +19,7 @@ export class DialogSubscribe extends TonicDialog { if (!el) return const app = this.props.parent + const notifications = document.querySelector('#notifications') const { event } = el.dataset @@ -32,7 +33,6 @@ export class DialogSubscribe extends TonicDialog { // union://foo?id=com.demo.project&org=test if (!bundleId || !cId) { - const notifications = document.querySelector('#notifications') notifications.create({ type: 'error', title: 'Error', @@ -48,10 +48,25 @@ export class DialogSubscribe extends TonicDialog { const sharedKey = await Encryption.createSharedKey(sharedSecret) const derivedKeys = await Encryption.createKeyPair(sharedKey) const subclusterId = Buffer.from(derivedKeys.publicKey) + const pathToProject = path.join(path.DATA, bundleId) + + try { + await fs.promises.mkdir(pathToProject, { recursive: true }) + } catch (err) { + notifications.create({ + type: 'error', + title: 'Error', + message: err.message + }) + super.hide() + return + } const project = { bundleId, + label: bundleId, waiting: true, + path: pathToProject, clusterId, subclusterId, sharedKey, @@ -62,8 +77,8 @@ export class DialogSubscribe extends TonicDialog { await app.initNetwork() const coProject = document.querySelector('app-project') - await this.close() - coProject.reRender() + await this.hide() + coProject.load() } } @@ -96,7 +111,7 @@ export class DialogSubscribe extends TonicDialog { + diff --git a/src/index.js b/src/index.js index 2193386..c6b473c 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,7 @@ import Database from './db/index.js' import { ViewHome } from './views/home.js' import { ViewImagePreview } from './views/image-preview.js' +import { ViewProjectSummary } from './views/project-summary.js' import { AppTerminal } from './components/terminal.js' import { AppProject } from './components/project.js' @@ -509,7 +510,7 @@ class AppView extends Tonic { File: Save: s + CommandOrControl - New Project: n + CommandOrControl + New Project: N + CommandOrControl Add Shared Project: G + CommandOrControl --- Reset Demo Project: _ @@ -570,7 +571,7 @@ class AppView extends Tonic { } case 'New Project': { - this.createProject() + await this.createProject() const coProject = document.querySelector('app-project') coProject.load() break @@ -671,7 +672,7 @@ class AppView extends Tonic { } if (event === 'create-new-project') { - this.createProject() + await this.createProject() const coProject = document.querySelector('app-project') coProject.load() } @@ -721,6 +722,7 @@ class AppView extends Tonic { + @@ -783,4 +785,5 @@ window.onload = () => { Tonic.add(DialogSubscribe) Tonic.add(ViewHome) Tonic.add(ViewImagePreview) + Tonic.add(ViewProjectSummary) } diff --git a/src/views/project-summary.js b/src/views/project-summary.js new file mode 100644 index 0000000..3a51d7d --- /dev/null +++ b/src/views/project-summary.js @@ -0,0 +1,42 @@ +import Tonic from '@socketsupply/tonic' + +class ViewProjectSummary extends Tonic { + show () { + this.classList.add('show') + } + + hide () { + this.classList.remove('show') + } + + async render () { + const app = this.props.parent + const currentProject = app.state.currentProject + + if (!currentProject) return this.html`` + + const { data: dataProject } = await app.db.projects.get(currentProject.projectId) + + let items + + if (dataProject.waiting) { + items = this.html` +
+

Waiting...

+
+ ` + } + + return this.html` +
+ ${currentProject.label} +
+
+ ${items} +
+ ` + } +} + +export default ViewProjectSummary +export { ViewProjectSummary }