11import React from 'react'
22import './antd.css'
3- import { Button , Layout , Menu , Space } from 'antd'
4- import { Content , Header } from 'antd/lib/layout/layout'
5- import * as icons from '@ant-design/icons'
6- import styled from 'styled-components'
3+ import { Layout } from 'antd'
4+ import { Content } from 'antd/lib/layout/layout'
75import Sheet from "./sheet/snippet/Sheet" ;
8- import { useTranslation } from 'react-i18next'
9- import Client , { EvaluationListener } from "./client" ;
10- import {
11- EvaluationError , EvaluationResult ,
12- MissingSources , StartEvaluationRequest
13- } from "@jsheets/protocol/src/jsheets/api/snippet_runtime_pb" ;
14- import { SheetSnippetComponentOutput } from "./sheet" ;
15- import { useDispatch } from "react-redux" ;
16- import { reportOutput } from "./sheet/state" ;
17-
18- const Logo = styled . span `
19- span:first-child {
20- color: #00758f;
21- }
22-
23- span:last-child {
24- color: #f29110;
25- }
26-
27- font-size: 30px;
28- font-weight: bolder;
29- 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;
30- `
31-
32- const StyledHeader = styled ( Header ) `
33- box-shadow: 0 5px 5px 0 rgb(230 230 230 / 90%);
34-
35- .ant-menu-horizontal {
36- border-bottom: none;
37- }
38- `
6+ import useEvaluate from "./sheet/useEvaluate" ;
7+ import Header from "./header/Header" ;
398
409export default function App ( ) {
41- const { t} = useTranslation ( )
42- const evaluator = useEvaluator ( )
10+ const [ evaluate , evaluating ] = useEvaluate ( )
4311 return (
4412 < Layout >
45- < StyledHeader style = { { background : '#fff' } } className = "header" >
46- < Menu theme = "light" style = { { marginRight : 'auto' } } mode = "horizontal" defaultSelectedKeys = { [ '2' ] } >
47- < Logo > < span > Java</ span > < span > Sheets</ span > </ Logo >
48- < Space style = { { marginLeft : 'auto' } } size = "middle" >
49- < Button type = "primary" ghost icon = { < icons . ShareAltOutlined /> } > { t ( 'menu.share' ) } </ Button >
50- </ Space >
51- </ Menu >
52- </ StyledHeader >
13+ < Header />
5314 < Content style = { { padding : 50 } } >
54- < Sheet onRun = { evaluator } />
15+ < Sheet running = { evaluating } onRun = { evaluate } />
5516 </ Content >
5617 </ Layout >
5718 )
58- }
59-
60- function useEvaluator ( ) {
61- const client = Client . create ( )
62- const dispatch = useDispatch ( )
63- return ( start : StartEvaluationRequest ) => {
64- console . log ( { start : start . toObject ( ) } )
65- client . evaluate (
66- start ,
67- new Listener ( ( componentId , output ) =>
68- dispatch ( reportOutput ( { componentId, output} ) ) )
69- )
70- }
71- }
72-
73- type ReportOutput = ( componentId : string , output : SheetSnippetComponentOutput ) => void
74-
75- class Listener implements EvaluationListener {
76- constructor ( private readonly reportOutput : ReportOutput ) { }
77-
78- onEnd ( ) : void { }
79-
80- onError = ( error : EvaluationError ) => {
81- console . log ( { error} )
82- this . reportOutput ( error . getComponentId ( ) , {
83- span : {
84- start : error . getSpan ( ) ?. getStart ( ) || 0 ,
85- end : error . getSpan ( ) ?. getEnd ( ) || 0
86- } ,
87- code : error . getKind ( ) ,
88- message : error . getMessage ( )
89- } )
90- }
91-
92- onMissingSources ( sources : MissingSources ) : void {
93- console . log ( { sources : sources . toObject ( ) } )
94- }
95-
96- onResult = ( result : EvaluationResult ) => {
97- console . log ( { result} )
98- this . reportOutput ( result . getComponentId ( ) , {
99- type : result . getKind ( ) === 1 ? 'info' : 'error' ,
100- message : result . getOutput ( )
101- } )
102- }
10319}
0 commit comments