Skip to content

Commit 84f1fbc

Browse files
authored
Merge pull request #9 from java-sheets/feature/execution
Fix sharing of sheets
2 parents f836dce + c0b9066 commit 84f1fbc

26 files changed

Lines changed: 399 additions & 312 deletions

‎docker-compose.dev.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
server:
4-
image: ehenoma/jsheets:latest
4+
image: ehenoma/jsheets:dev
55
build:
66
# Make sure to run 'gradle copyDependencies' before building
77
dockerfile: server/deploy/Dockerfile

‎website/.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ npm-debug.log*
2323
yarn-debug.log*
2424
yarn-error.log*
2525

26-
website/src/editor/java/parser.js
27-
website/src/editor/java/parser.terms.js
26+
parser.js
27+
parser.terms.js

‎website/package-lock.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎website/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/react-router-dom": "^5.3.0",
1818
"@types/uuid": "^8.3.1",
1919
"antd": "^4.16.13",
20+
"copy-to-clipboard": "^3.3.1",
2021
"google-protobuf": "^3.18.0",
2122
"i18next": "^20.6.1",
2223
"install": "^0.13.0",

‎website/src/App.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback} from 'react'
1+
import React, {useCallback, useState} from 'react'
22
import {Layout} from 'antd'
33
import {Content} from 'antd/lib/layout/layout'
44
import Sheet from './sheet/Sheet'
@@ -11,16 +11,28 @@ import {
1111
} from 'react-router-dom'
1212
import {useShare} from './sheet/useShare'
1313
import ImportedSheet from './sheet/ImportedSheet'
14+
import ShareModal from './sheet/ShareModal'
1415

1516
export default function App() {
1617
const [evaluate, evaluating] = useEvaluate()
1718
const history = useHistory()
18-
const callback = useCallback(created => history.push(`/s/${created.id}`), [history])
19+
const [sharedId, setSharedId] = useState('')
20+
const [shareVisible, setShareVisible] = useState(false)
21+
const callback = useCallback(created => {
22+
history.push(`/s/${created.id}`)
23+
setShareVisible(true)
24+
setSharedId(created.id)
25+
}, [history])
1926
const [share, captureSnippet] = useShare(callback)
2027
return (
2128
<Layout>
2229
<Header onShare={share}/>
2330
<Content style={{padding: '0 50px 50px 50px'}}>
31+
<ShareModal
32+
visible={shareVisible}
33+
onVisibilityChange={setShareVisible}
34+
sheetId={sharedId}
35+
/>
2436
<Switch>
2537
<Route path="/s/:sheetId">
2638
<ImportedSheet

‎website/src/client/index.ts‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
EvaluateRequest
99
} from "@jsheets/protocol/src/jsheets/api/snippet_runtime_pb";
1010
import * as SheetProtocol from "@jsheets/protocol/src/jsheets/api/sheet_pb";
11-
import {Sheet} from '../sheet'
11+
import {ComponentState, SheetState, SnippetState} from '../sheet'
1212

1313
export interface EvaluationListener {
1414
onEnd(): void
@@ -108,7 +108,7 @@ class WebSocketEvaluation implements Evaluation {
108108
export class SheetClient {
109109
constructor(private readonly baseUrl: string) { }
110110

111-
async find(id: string): Promise<Sheet> {
111+
async find(id: string): Promise<SheetState> {
112112
const call = await fetch(`${this.baseUrl}/api/v1/sheets/${id}`)
113113
if (call.ok) {
114114
const body = await call.json()
@@ -117,7 +117,7 @@ export class SheetClient {
117117
throw new Error(`${call.status}`)
118118
}
119119

120-
async post(snippet: Partial<SheetProtocol.Sheet.AsObject>): Promise<Sheet> {
120+
async post(snippet: Partial<SheetProtocol.Sheet.AsObject>): Promise<SheetState> {
121121
convertRequest(snippet)
122122
const call = await fetch(`${this.baseUrl}/api/v1/sheets`, {
123123
method: 'POST',
@@ -131,28 +131,34 @@ export class SheetClient {
131131
}
132132
}
133133

134-
function createSheetFromResponse(response: Record<string, any>): Sheet {
134+
function createSheetFromResponse(response: Record<string, any>): SheetState {
135135
convertResponse(response)
136136
const message = response as SheetProtocol.Sheet.AsObject
137+
const snippets: Record<string, SnippetState> = {}
138+
for (const snippet of message.snippetsList) {
139+
const components: Record<string, ComponentState> = {}
140+
for (const component of snippet.componentsList) {
141+
const kind = (component.kind as unknown) as string
142+
components[component.id] = {
143+
id: component.id,
144+
order: component.order,
145+
type: kind.toLowerCase() === "code" ? "code" : "text",
146+
content: component.content
147+
}
148+
}
149+
snippets[snippet.id] = {
150+
id: snippet.id,
151+
order: snippet.order,
152+
title: snippet.name,
153+
components
154+
}
155+
}
137156
return {
138157
id: message.id,
139158
title: message.title,
140159
description: message.description,
141-
snippets: message.snippetsList.map(snippet => ({
142-
id: snippet.id,
143-
order: snippet.order,
144-
title: snippet.name,
145-
components: snippet.componentsList.map(component => {
146-
const kind = (component.kind as unknown) as string
147-
return {
148-
id: component.id,
149-
order: component.order,
150-
type: kind.toLowerCase(),
151-
content: component.content
152-
}
153-
})
154-
}))
155-
} as Sheet
160+
snippets: snippets
161+
} as SheetState
156162
}
157163

158164
function convertResponse(object: Record<string, any>) {

‎website/src/editor/java/language.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import {styleTags, Tag, tags as t} from "@codemirror/highlight"
1111

1212
// Make sure that the code is generated (npm run build-grammar)
13-
import {parser} from "./parser";
13+
import {parser} from "./parser"
1414

1515
export const customTags = {
1616
call: Tag.define(),

‎website/src/editor/java/parser.js‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎website/src/editor/java/parser.terms.js‎

Lines changed: 0 additions & 116 deletions
This file was deleted.

‎website/src/header/Logo.style.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const Logo = styled.span`
99
color: #f29110;
1010
}
1111
12+
cursor: pointer;
1213
font-size: 30px;
1314
font-weight: bolder;
1415
font-family: 'Titillium Web', Roboto, 'Helvetica Neue', 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol' !important;

0 commit comments

Comments
 (0)