1919
2020 import Button , {Label } from " @smui/button" ;
2121 import Icon from ' @smui/textfield/icon' ;
22- import jwt_decode , {JwtPayload } from " jwt-decode" ;
22+ import jwt_decode from " jwt-decode" ;
23+ import insane from " insane" ;
2324
2425 export let id: string = " " ;
2526
2627 const token = localStorage .getItem (" key" );
27- const decoded = jwt_decode < JwtPayload > (token );
28+ const decoded = jwt_decode (token );
2829
2930 function getCommunication() {
3031 fetch (` ${baseurl }/communication/get/${id } ` , {headers: {" Authorization" : " Bearer " + localStorage .getItem (" key" )}})
115116 }
116117 </script >
117118
119+ {#if rerenderDrawer }<Drawer active ={" communication" + id } communicationActive ={id } openDialog ={openDialog } />{/if }
120+ <AppContent class =" app-content" >
121+ <main class =" main-content" >
122+ {#if comm }
123+ <h1 >{comm .Title }</h1 >
124+ {#each comm .Messages as message }
125+ <div style =" white-space: nowrap;" >
126+ <Avatar name ={message .UserName } style =" display: inline-block;" />
127+ <h2 style ="display: inline-block; text-align: center;" >{message .UserName }</h2 >
128+ {#if message .UserID === decoded [" user_id" ]}
129+ <Meta style =" display: inline-block;" >
130+ <Button on:click ={() => deleteMessage (message .ID )}>
131+ <Icon class =" material-icons" >delete</Icon >
132+ <Label >Izbriši</Label >
133+ </Button >
134+ </Meta >
135+ <Meta style =" display: inline-block;" >
136+ <Button on:click ={() => {
137+ messageEditingId = message .ID ;
138+ newMessageValue = message .Body ;
139+ }}>
140+ <Icon class =" material-icons" >edit</Icon >
141+ <Label >Uredi</Label >
142+ </Button >
143+ </Meta >
144+ {/if }
145+ </div >
146+ {@html insane (marked .marked (message .Body ))}
147+ {/each }
148+ <hr >
149+ <Textfield
150+ textarea
151+ bind:value ={newMessageValue }
152+ style =" width: 100%;"
153+ />
154+ {#if newMessageValue !== " " }
155+ <h2 >Predogled</h2 >
156+ {@html insane (marked .marked (newMessageValue ))}
157+ {/if }
158+ <p />
159+ {#if messageEditingId === undefined }
160+ <Button on:click ={() => {
161+ let fd = new FormData ();
162+ fd .append (" body" , newMessageValue )
163+ fetch (` ${baseurl }/communication/get/${id }/message/new ` , {headers: {" Authorization" : " Bearer " + localStorage .getItem (" key" )}, body: fd , method: " POST" })
164+ .then ((r ) => {
165+ newMessageValue = " " ;
166+ getCommunication ();
167+ });
168+ }}>
169+ <Icon class =" material-icons" >send</Icon >
170+ <Label >Pošlji</Label >
171+ </Button >
172+ {:else }
173+ <Button on:click ={() => editMessage ()}>
174+ <Icon class =" material-icons" >done</Icon >
175+ <Label >Končaj z urejanjem</Label >
176+ </Button >
177+ <Button on:click ={() => {
178+ messageEditingId = undefined ;
179+ newMessageValue = " " ;
180+ }}>
181+ <Icon class =" material-icons" >close</Icon >
182+ <Label >Končaj z urejanjem brez shranjevanja sprememb</Label >
183+ </Button >
184+ {/if }
185+ {/if }
186+ </main >
187+ </AppContent >
188+
118189<Dialog
119190 bind:open
120191 aria-labelledby =" simple-title"
216287 </Label >
217288 </Button >
218289 </Actions >
219- </Dialog >
220-
221- {#if rerenderDrawer }
222- <Drawer active ={" communication" + id } communicationActive ={id } openDialog ={openDialog } />
223- {/if }
224- <AppContent class =" app-content" >
225- <main class =" main-content" >
226- {#if comm }
227- <h1 >{comm .Title }</h1 >
228- {#each comm .Messages as message }
229- <div style =" white-space: nowrap;" >
230- <Avatar name ={message .UserName } style =" display: inline-block;" />
231- <h2 style ="display: inline-block; text-align: center;" >{message .UserName }</h2 >
232- {#if message .UserID === decoded [" user_id" ]}
233- <Meta style =" display: inline-block;" >
234- <Button on:click ={() => deleteMessage (message .ID )}>
235- <Icon class =" material-icons" >delete</Icon >
236- <Label >Izbriši</Label >
237- </Button >
238- </Meta >
239- <Meta style =" display: inline-block;" >
240- <Button on:click ={() => {
241- messageEditingId = message .ID ;
242- newMessageValue = message .Body ;
243- }}>
244- <Icon class =" material-icons" >edit</Icon >
245- <Label >Uredi</Label >
246- </Button >
247- </Meta >
248- {/if }
249- </div >
250- {@html marked .marked (message .Body )}
251- {/each }
252- <hr >
253- <Textfield
254- textarea
255- bind:value ={newMessageValue }
256- style =" width: 100%;"
257- />
258- {#if newMessageValue !== " " }
259- <h2 >Predogled</h2 >
260- {@html marked .marked (newMessageValue )}
261- {/if }
262- <p />
263- {#if messageEditingId === undefined }
264- <Button on:click ={() => {
265- let fd = new FormData ();
266- fd .append (" body" , newMessageValue )
267- fetch (` ${baseurl }/communication/get/${id }/message/new ` , {headers: {" Authorization" : " Bearer " + localStorage .getItem (" key" )}, body: fd , method: " POST" })
268- .then ((r ) => {
269- newMessageValue = " " ;
270- getCommunication ();
271- });
272- }}>
273- <Icon class =" material-icons" >send</Icon >
274- <Label >Pošlji</Label >
275- </Button >
276- {:else }
277- <Button on:click ={() => editMessage ()}>
278- <Icon class =" material-icons" >done</Icon >
279- <Label >Končaj z urejanjem</Label >
280- </Button >
281- <Button on:click ={() => {
282- messageEditingId = undefined ;
283- newMessageValue = " " ;
284- }}>
285- <Icon class =" material-icons" >close</Icon >
286- <Label >Končaj z urejanjem brez shranjevanja sprememb</Label >
287- </Button >
288- {/if }
289- {/if }
290- </main >
291- </AppContent >
290+ </Dialog >
0 commit comments