Skip to content

Commit

Permalink
wip project sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Mar 22, 2024
1 parent 12f5a62 commit 8b9b207
Show file tree
Hide file tree
Showing 26 changed files with 534 additions and 421 deletions.
5 changes: 1 addition & 4 deletions src/components/editor.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import fs from 'socket:fs'
import path from 'socket:path'
import { lookup } from 'socket:mime'

import * as monaco from 'monaco-editor'
import Tonic from '@socketsupply/tonic'

import { resizePNG } from '../lib/icon.js'

function rgbaToHex (rgbaString) {
const rgbaValues = rgbaString.match(/\d+/g)

Expand Down Expand Up @@ -216,7 +213,7 @@ class AppEditor extends Tonic {
return
}

coTerminal.info(`Settings file updated.`)
coTerminal.info('Settings file updated.')
app.activatePreviewWindows()
}

Expand Down
132 changes: 0 additions & 132 deletions src/components/image-preview.js

This file was deleted.

31 changes: 24 additions & 7 deletions src/components/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function cp (srcDir, destDir) {
const destPath = path.join(destDir, file.name)

if (file.isDirectory()) {
await copyDirectory(srcPath, destPath)
await cp(srcPath, destPath)
} else {
await fs.promises.copyFile(srcPath, destPath, fs.constants.COPYFILE_FICLONE)
}
Expand Down Expand Up @@ -462,7 +462,6 @@ class AppProject extends Tonic {

async onSelection (node, isToggle) {
if (!isToggle) {

const projectNode = this.getProjectNode(node)

// Check if the project has changed, refresh the props component
Expand All @@ -476,10 +475,20 @@ class AppProject extends Tonic {

this.state.currentProject = projectNode.id

const coImagePreview = document.querySelector('view-image-preview')
const coHome = document.querySelector('view-home')

coImagePreview.hide()
coHome.hide()

if (projectNode.id === 'home') {
coHome.show()
return
}

// Check if this is an image type that we can present
const ext = path.extname(node.id)
const type = await lookup(ext.slice(1))
const coImagePreview = document.querySelector('app-image-preview')

if (type.length) {
if (/image/.test(type[0].mime)) {
Expand All @@ -489,8 +498,6 @@ class AppProject extends Tonic {
}
}

coImagePreview.hide()

// Load the code editor
const coEditor = document.querySelector('app-editor')
coEditor.loadProjectNode(node)
Expand Down Expand Up @@ -568,12 +575,24 @@ class AppProject extends Tonic {

async load () {
const oldState = this.state.tree
const oldChild = this.getNodeByProperty('id', 'home', oldState)

const tree = {
id: 'root',
children: []
}

tree.children.push({
id: 'home',
parent: tree,
selected: oldChild?.selected ?? 0,
state: oldChild?.state ?? 0,
isDirectory: false,
icon: 'home-icon',
label: 'Home',
children: []
})

const readDir = async (dirPath, parent) => {
let entries = []

Expand Down Expand Up @@ -627,8 +646,6 @@ class AppProject extends Tonic {
}
}

const app = document.querySelector('app-view')

try {
await readDir(path.join(path.DATA, 'projects'), tree)
this.state.tree = tree
Expand Down
Loading

0 comments on commit 8b9b207

Please sign in to comment.