Commit 40e111eb by Amirouche

frontend: setup view+route dispatch

parent 5ee9be1c
Showing with 29 additions and 5 deletions
......@@ -9,12 +9,36 @@
(lambda (event)
(+ 1 model)))
(define (view-index model mc)
`(p "Héllo"))
(define (view-login model mc)
`(div (@ (id . "content"))
(h1 "Login")
(input (@ (type . "password")))))
(define routes `(("/" ,identity-controller ,view-index)
("/login" ,identity-controller ,view-login)))
(define (make-routes routes)
(map (lambda (route) (cons (car route) (cadr route))) routes))
(define (make-views routes)
(map (lambda (route) (cons (car route) (caddr route))) routes))
(define route->view (make-views routes))
(define (view model mc)
(pk model)
(pk 'view model)
`(div (@ (id . "shell"))
(div (@ (id . "container"))
,(case (ref* model 'location 'route)
((unknown) `(h1 "Error 404: Unknown route " ,(document-location-pathname)))
(else '(p "Welcome to my place in the cyberspace"))))))
,(let ((route (pk 'route (ref* model 'location 'route))))
(if (eq? route 'unknown)
`(h1 "Error 404: Unknown route " ,(document-location-pathname))
(let ((view (ref route->view route)))
(if view
(view model mc)
'(p "no route defined yet for "))))))))
(create-app* container init view `(("/" . ,identity-controller)))
(create-app* container init view (make-routes routes))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment