Skip to content

Commit e78cf38

Browse files
committed
improve sharing
1 parent 8d5e726 commit e78cf38

File tree

12 files changed

+203
-114
lines changed

12 files changed

+203
-114
lines changed

src/components/editor.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class AppEditor extends Tonic {
263263
const coTerminal = document.querySelector('app-terminal')
264264
const coProperties = document.querySelector('app-properties')
265265
const coTabs = document.querySelector('editor-tabs')
266+
const coEditor = document.querySelector('app-editor')
266267

267268
if (!coTabs.tab) return
268269

@@ -278,13 +279,11 @@ class AppEditor extends Tonic {
278279
}
279280

280281
coTerminal.info('Settings file updated.')
282+
coEditor.refreshColors()
281283
app.activatePreviewWindows()
282284
}
283285

284-
clearTimeout(this.debouncePropertiesRerender)
285-
this.debouncePropertiesRerender = setTimeout(() => {
286-
coProperties.reRender()
287-
}, 512)
286+
coProperties.reRender()
288287

289288
try {
290289
await fs.promises.writeFile(coTabs.tab.path, value)
@@ -364,7 +363,7 @@ class AppEditor extends Tonic {
364363
{ token: 'variable.predefined', foreground: '4864AA' },
365364
{ token: 'variable.parameter', foreground: '9CDCFE' },
366365
{ token: 'constant', foreground: '569CD6' },
367-
{ token: 'comment', foreground: '338c32' },
366+
{ token: 'comment', foreground: colors.secondary },
368367
{ token: 'number', foreground: colors.accent },
369368
{ token: 'number.hex', foreground: '5BB498' },
370369
{ token: 'regexp', foreground: 'B46695' },

src/components/git-status.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Tonic from '@socketsupply/tonic'
2+
import { exec } from 'socket:child_process'
3+
4+
// TODO(@heapwolf): this should be a component
5+
class GitStatus extends Tonic {
6+
async render () {
7+
const app = this.props.app
8+
const currentProject = app.state.currentProject
9+
10+
const { data: dataProject } = await app.db.projects.get(currentProject.projectId)
11+
12+
let gitStatus = { stdout: '', stderr: '' }
13+
14+
//
15+
// Try to get the status of the project to tell the user what
16+
// has changed and help them decide if they should publish.
17+
//
18+
try {
19+
gitStatus = await exec('git status --porcelain', { cwd: dataProject.path })
20+
} catch (err) {
21+
gitStatus.stderr = err.message
22+
}
23+
24+
if (gitStatus?.stderr.includes('command not found')) {
25+
return this.html`
26+
<tonic-toaster-inline
27+
id="git-not-installed"
28+
dismiss="false"
29+
display="true"
30+
>Git is not installed and is required to use this program.
31+
</tonic-toaster-inline>
32+
`
33+
}
34+
35+
return this.html`
36+
<h2>Git Integration</h2>
37+
<tonic-textarea
38+
id="git-status"
39+
rows="10"
40+
label="Git Status"
41+
readonly="true"
42+
resize="none"
43+
>${gitStatus.stderr || gitStatus.stdout}</tonic-textarea>
44+
`
45+
}
46+
}
47+
48+
export default GitStatus
49+
export { GitStatus }

src/components/patch-requests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Tonic from '@socketsupply/tonic'
2+
import { exec } from 'socket:child_process'
3+
4+
class PatchRequests extends Tonic {
5+
async render () {
6+
const app = this.props.app
7+
8+
const { data: dataPatches } = await app.db.patches.readAll()
9+
10+
let patches = []
11+
12+
for (const [patchId, patch] of dataPatches.entries()) {
13+
patches.push(this.html`
14+
<tr>
15+
<td>
16+
<tonic-button type="icon" symbol-id="plus-icon" data-event="apply" data-value="${patchId}"></tonic-button>
17+
<tonic-button type="icon" symbol-id="edit-icon" data-event="load" data-value="${patchId}"></tonic-button>
18+
</td>
19+
<td>${patch.author}</td>
20+
<td>${patch.date}</td>
21+
<td>${patch.parent}</td>
22+
<td>${patch.message}</td>
23+
</tr>
24+
`)
25+
}
26+
27+
return this.html`
28+
<h2>Patch Requests</h2>
29+
<table class="patches">
30+
<thead>
31+
<th>Actions</th>
32+
<th>Author</th>
33+
<th>Date</th>
34+
<th>Parent</th>
35+
<th>Commit Message</th>
36+
</thead>
37+
<tbody>
38+
${patches}
39+
<tbody>
40+
</table>
41+
`
42+
}
43+
}
44+
45+
export default PatchRequests
46+
export { PatchRequests }

src/components/project.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class AppProject extends Tonic {
334334
if (!node) this.getNodeFromElement(el.parentElement)
335335
if (!node) return
336336

337-
if (node.nonMovable && !node.type === 'project') return
337+
if (node.nonMovable && node.type !== 'project') return
338338

339339
const container = el.querySelector('.label')
340340

@@ -726,6 +726,7 @@ class AppProject extends Tonic {
726726
selected: oldChild?.selected ?? 0,
727727
state: oldChild?.state ?? 0,
728728
id: project.path,
729+
bundleId: project.bundleId,
729730
projectId,
730731
label: project.label,
731732
isDirectory: false,
@@ -735,6 +736,11 @@ class AppProject extends Tonic {
735736
children: []
736737
}
737738

739+
if (!this.props.parent.state.currentProject) {
740+
this.props.parent.state.currentProject = node
741+
this.props.parent.reloadPreviewWindows()
742+
}
743+
738744
tree.children.push(node)
739745

740746
if (project.path) {

src/components/properties.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,6 @@ import process from 'socket:process'
66
import Config from '../lib/config.js'
77

88
class AppProperties extends Tonic {
9-
async saveSettingsFile () {
10-
const app = this.props.parent
11-
const currentProject = app.state.currentProject
12-
const pathToSettingsFile = path.join(path.DATA, 'projects', 'settings.json')
13-
const coTabs = document.querySelector('editor-tabs')
14-
const coEditor = document.querySelector('app-editor')
15-
16-
// if the user currently has the config file open in the editor...
17-
if (coTabs.tab?.isRootSettingsFile) {
18-
try {
19-
coEditor.value = JSON.stringify(app.state.settings, null, 2)
20-
} catch (err) {
21-
return notifications.create({
22-
type: 'error',
23-
title: 'Unable to save config file',
24-
message: err.message
25-
})
26-
}
27-
}
28-
29-
try {
30-
const str = JSON.stringify(app.state.settings)
31-
await fs.promises.writeFile(pathToSettingsFile, str)
32-
} catch (err) {
33-
return notifications?.create({
34-
type: 'error',
35-
title: 'Error',
36-
message: 'Unable to update settings'
37-
})
38-
}
39-
}
40-
419
async change (e) {
4210
const el = Tonic.match(e.target, '[data-event]')
4311
if (!el) return
@@ -60,7 +28,7 @@ class AppProperties extends Tonic {
6028
previewWindow.active = !previewWindow.active
6129
}
6230

63-
await this.saveSettingsFile()
31+
await app.saveSettingsFile()
6432
app.activatePreviewWindows()
6533
}
6634

src/components/publish.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,10 @@ export class DialogPublish extends TonicDialog {
1919
}
2020
}
2121

22-
async getProject () {
23-
const app = this.props.parent
24-
const currentProject = app.state.currentProject
25-
if (!currentProject) return
26-
27-
let config = new Config(currentProject.id)
28-
let bundleId = await config.get('meta', 'bundle_identifier')
29-
bundleId = bundleId.replace(/"/g, '')
30-
31-
const { data: hasProject } = await app.db.projects.has(bundleId)
32-
33-
if (hasProject) {
34-
const { data: dataProject } = await app.db.projects.get(bundleId)
35-
return dataProject
36-
}
37-
}
38-
3922
async publish (type, value) {
4023
const app = this.props.parent
41-
const dataProject = await this.getProject()
24+
const currentProject = app.state.currentProject
25+
const { data: dataProject } = await app.db.projects.get(currentProject.bundleId)
4226

4327
const opts = {
4428
// TODO(@heapwolf): probably chain with previousId
@@ -197,8 +181,8 @@ export class DialogPublish extends TonicDialog {
197181
this.publish('patch', Buffer.from(output.stdout)) // into the background
198182
}
199183

200-
const coProperties = document.querySelector('app-properties')
201-
coProperties.reRender()
184+
const coProjectSummary = document.querySelector('view-project-summary')
185+
coProjectSummary.reRender()
202186
}
203187

204188
return this.html`

src/css/component-patch-requests.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
patch-requests table {
2+
font-family: var(--tonic-monospace);
3+
width: 100%;
4+
}
5+
6+
patch-requests table thead {
7+
text-align: left;
8+
}
9+
10+
patch-requests table tr th {
11+
height: 40px;
12+
border-bottom: 1px solid var(--tonic-border);
13+
color: var(--tonic-medium, #999);
14+
font-weight: 500;
15+
font: 12px/14px var(--tonic-subheader, 'Arial', sans-serif);
16+
text-transform: uppercase;
17+
letter-spacing: 1px;
18+
}
19+
20+
patch-requests table td {
21+
padding: 8px 0px;
22+
border-bottom: 1px solid var(--tonic-border);
23+
}
24+
25+
patch-requests table td {
26+
min-width: 120px;
27+
}
28+
29+
patch-requests table tr:last-of-type td {
30+
border-bottom: none;
31+
}

src/css/theme.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ body {
1717
--tonic-window: rgba(255, 255, 255, 1);
1818
--tonic-accent: rgba(56, 185, 255, 1);
1919
--tonic-primary: rgba(54, 57, 61, 1);
20-
--tonic-secondary: rgba(232, 232, 228, 1);
20+
--tonic-secondary: rgba(190, 190, 190, 1);
2121
--tonic-light: rgba(153, 157, 160, 1);
2222
--tonic-medium: rgba(153, 157, 160, 1);
2323
--tonic-shadow: rgba(150, 150, 150, 0.25);
@@ -47,7 +47,7 @@ body {
4747
--tonic-window: rgba(46, 46, 46, 1);
4848
--tonic-accent: rgba(56, 185, 255, 1);
4949
--tonic-primary: rgba(255, 255, 255, 1);
50-
--tonic-secondary: rgba(120, 120, 120, 1);
50+
--tonic-secondary: rgba(93, 93, 93, 1);
5151
--tonic-medium: rgba(153, 157, 160, 1);
5252
--tonic-dark: rgba(28, 28, 28, 1);
5353
--tonic-shadow: rgba(0, 0, 0, 0.3);

src/css/view-project-summary.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ view-project-summary.show {
1212
z-index: 30;
1313
}
1414

15+
view-project-summary h2 {
16+
font-size: 20px;
17+
text-transform: uppercase;
18+
color: var(--tonic-info);
19+
font-weight: 100;
20+
}
21+
1522
view-project-summary header span {
1623
width: 100%;
1724
text-align: center;
@@ -42,7 +49,7 @@ view-project-summary .sharing {
4249
display: grid;
4350
grid-template-columns: 1fr 1fr 1fr 1fr;
4451
gap: 20px;
45-
grid-template-rows: auto auto 1fr;
52+
grid-template-rows: auto auto auto 1fr;
4653
align-items: end;
4754
}
4855

@@ -62,7 +69,12 @@ view-project-summary #publish {
6269
grid-area: 2 / 4;
6370
}
6471

65-
view-project-summary view-git-status {
72+
view-project-summary git-status {
6673
grid-area: 3 / span 4;
6774
align-self: start;
6875
}
76+
77+
view-project-summary patch-requests {
78+
grid-area: 4 / span 4;
79+
align-self: start;
80+
}

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<link rel="stylesheet" href="css/index.css">
2424

2525
<link rel="stylesheet" href="css/component-editor.css">
26+
<link rel="stylesheet" href="css/component-patch-requests.css">
2627
<link rel="stylesheet" href="css/component-properties.css">
2728
<link rel="stylesheet" href="css/component-publish.css">
2829
<link rel="stylesheet" href="css/component-subscribe.css">

0 commit comments

Comments
 (0)