File tree Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Original file line number Diff line number Diff line change 1212
1313 export let data: PageData ;
1414 let { timerData } = data ;
15- let submitResult: Promise <Timer > | undefined ;
15+ let submitResult: Promise <Timer | void > = Promise . resolve () ;
1616
1717 $ : {
1818 if (browser && ! localStorage .getItem (' token' )) goto (' /manage/login' );
5555 <button
5656 class =" btn-icon"
5757 on:click ={() => {
58- submitResult = undefined ;
58+ submitResult = Promise . resolve () ;
5959 }}><Fa icon ={faClose } /></button
6060 >
6161 </aside >
7171 <button
7272 class =" btn-icon"
7373 on:click ={() => {
74- submitResult = undefined ;
74+ submitResult = Promise . resolve () ;
7575 }}><Fa icon ={faClose } /></button
7676 >
7777 </div >
8080</div >
8181
8282<div class =" m-auto text-center" >
83- Alternatively, you can <a href =" /" >view an existing timer</a > or
84- <a href =" /manage/login" >manage an existing timer</a >
83+ Alternatively, you can <a href =" /" >view an existing timer</a >,
84+ <a href =" /manage/login" >manage a diffrent existing timer</a > or
85+ <a href =" /manage/create" >create a new timer</a >
8586</div >
Original file line number Diff line number Diff line change 1111
1212 export let data: PageData ;
1313 const { fetch } = data ;
14- let submitResult: Promise <string > | undefined ;
14+ let submitResult: Promise <string | void > = Promise .resolve ();
15+
16+ interface ErrorMessages {
17+ [key : number ]: string ;
18+ }
19+
20+ const errorMessages: ErrorMessages = {
21+ 409 : ' A timer with that name already exists'
22+ };
1523
1624 const onSubmit = (timerData : TimerCreationRequest ) => {
1725 submitResult = fetch (` ${get (API_URL )}/timer ` , {
2230 }
2331 })
2432 .then ((res ) => {
25- if (! res .ok ) {
33+ if (! res .ok && res .status in errorMessages ) {
34+ throw new Error (errorMessages [res .status ]);
35+ } else if (! res .ok ) {
2636 throw new Error (res .statusText );
2737 }
38+
2839 return res .json ();
2940 })
3041 .then ((data ) => {
6172 <button
6273 class =" btn-icon"
6374 on:click ={() => {
64- submitResult = undefined ;
75+ submitResult = Promise . resolve () ;
6576 }}><Fa icon ={faClose } /></button
6677 >
6778 </aside >
Original file line number Diff line number Diff line change 1010
1111 export let data: PageData ;
1212 const { fetch } = data ;
13- let submitResult: Promise <string > | undefined ;
13+ let submitResult: Promise <string | void > = Promise . resolve () ;
1414
1515 const onSubmit = async (id : string , password : string ) => {
1616 submitResult = fetch (` ${get (API_URL )}/timer/token ` , {
6262 <button
6363 class =" btn-icon"
6464 on:click ={() => {
65- submitResult = undefined ;
65+ submitResult = Promise . resolve () ;
6666 }}><Fa icon ={faClose } /></button
6767 >
6868 </aside >
You can’t perform that action at this time.
0 commit comments