@@ -14,6 +14,8 @@ var _uuid = require("uuid");
14
14
var _ServerSideProps = require ( "./ServerSideProps" ) ;
15
15
var _config = require ( "../config" ) ;
16
16
var _jsonwebtoken = _interopRequireDefault ( require ( "jsonwebtoken" ) ) ;
17
+ var _ExpressServer = require ( "./ExpressServer" ) ;
18
+ var _instances = require ( "../instances" ) ;
17
19
var _jsxRuntime = require ( "@state-less/react-server/dist/jsxRenderer/jsx-runtime" ) ;
18
20
var _excluded = [ "order" , "points" , "iat" ] ;
19
21
function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; enumerableOnly && ( symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ) , keys . push . apply ( keys , symbols ) ; } return keys ; }
@@ -131,6 +133,7 @@ var Todo = function Todo(_ref3, _ref4) {
131
133
color : color
132
134
} ) ) ;
133
135
} ;
136
+ console . log ( 'Render todo' , todo ) ;
134
137
var toggle = function toggle ( ) {
135
138
var _user3 ;
136
139
var store = _reactServer . Dispatcher . getCurrent ( ) . getStore ( ) ;
@@ -147,6 +150,7 @@ var Todo = function Todo(_ref3, _ref4) {
147
150
lastModified : Date . now ( ) ,
148
151
creditedValuePoints : comp ? 0 : valuePoints
149
152
} ) ;
153
+ console . log ( 'toggling' , todo , newTodo ) ;
150
154
setTodo ( newTodo ) ;
151
155
var newItems = ! comp ? [ ] . concat ( ( 0 , _toConsumableArray2 [ "default" ] ) ( lastCompleted . value [ valuePoints ] || [ ] ) , [ newTodo ] ) : ( lastCompleted . value [ valuePoints ] || [ ] ) . filter ( function ( i ) {
152
156
return i . id !== todo . id ;
@@ -157,6 +161,7 @@ var Todo = function Todo(_ref3, _ref4) {
157
161
} ) ;
158
162
lastCompleted . value = _objectSpread ( _objectSpread ( { } , lastCompleted . value || { } ) , { } , ( 0 , _defineProperty2 [ "default" ] ) ( { } , valuePoints , filtered ) ) ;
159
163
points . value += comp ? - todo . creditedValuePoints : valuePoints ;
164
+ return newTodo ;
160
165
} ;
161
166
var archive = function archive ( ) {
162
167
if ( todo . archived ) return ;
@@ -225,7 +230,27 @@ var Todo = function Todo(_ref3, _ref4) {
225
230
setDueTime : setDueTime ,
226
231
type : "Todo" ,
227
232
createdAt : createdAt ,
228
- lastModified : todo . lastModified
233
+ lastModified : todo . lastModified ,
234
+ children : ( 0 , _jsxRuntime . jsx ) ( _ExpressServer . Route , {
235
+ todo : todo ,
236
+ app : _instances . app ,
237
+ path : "/todos/" . concat ( id , "/toggle" ) ,
238
+ get : function get ( req , res ) {
239
+ console . log ( 'Hello from HTTP' ) ;
240
+ var todo = toggle ( ) ;
241
+ res . send ( todo ) ;
242
+ } ,
243
+ authenticate : function authenticate ( req , res , next ) {
244
+ console . log ( 'Hello from HTTP' ) ;
245
+ // Authenticate the http request
246
+ ( 0 , _reactServer . authenticate ) ( req . headers , _config . JWT_SECRET ) ;
247
+ // Make sure the client is the same
248
+ if ( req . headers [ 'x-unique-id' ] !== clientId ) {
249
+ throw new Error ( 'Unauthorized' ) ;
250
+ }
251
+ next ( ) ;
252
+ }
253
+ } , "test" )
229
254
} ) , ( 0 , _reactServer . clientKey ) ( "" . concat ( id , "-todo" ) , context ) ) ;
230
255
} ;
231
256
exports . Todo = Todo ;
0 commit comments