1- import solidUi from 'solid-ui'
21import { S } from 'surplus'
32import { DataSignal } from 's-js/src/S'
4-
5- const { store } = solidUi
3+ import { loadMarkdown , saveMarkdown } from './markdown.service'
64
75export enum STATE {
86 'LOADING' ,
@@ -14,17 +12,13 @@ export class MarkdownController {
1412 public state : DataSignal < STATE >
1513 public rawText : DataSignal < string >
1614
17- // public renderedText: DataSignal<string>
18-
1915 constructor ( private subjectUri : string ) {
2016 this . state = S . value ( STATE . LOADING )
2117 this . rawText = S . value ( '' )
22- // this.renderedText = S.value('')
2318
24- store . fetcher . webOperation ( 'GET' , subjectUri )
25- . then ( ( response : any ) => {
26- this . rawText ( response . responseText )
27- // this.renderedText(marked(response.responseText))
19+ loadMarkdown ( subjectUri )
20+ . then ( ( responseText ) => {
21+ this . rawText ( responseText )
2822 this . state ( STATE . RENDERING )
2923 } )
3024 }
@@ -33,20 +27,9 @@ export class MarkdownController {
3327 const wasEditing = this . state ( ) === STATE . EDITING
3428 if ( wasEditing ) {
3529 this . state ( STATE . LOADING )
36- return MarkdownController . save ( this . subjectUri , this . rawText ( ) )
30+ return saveMarkdown ( this . subjectUri , this . rawText ( ) )
3731 . then ( ( ) => this . state ( STATE . RENDERING ) )
3832 }
3933 this . state ( STATE . EDITING )
4034 }
41-
42- update ( fieldName : string ) : void {
43- console . log ( fieldName , this )
44- }
45-
46- static save ( uri : string , content : string ) : Promise < any > {
47- return store . fetcher . webOperation ( 'PUT' , uri , {
48- data : content ,
49- contentType : 'text/markdown; charset=UTF-8'
50- } )
51- }
5235}
0 commit comments