diff of eb29fc1a56a685eb5e3b4b3b33685cde0b3f2371

eb29fc1a56a685eb5e3b4b3b33685cde0b3f2371
diff --git a/aggressive-murja.asd b/aggressive-murja.asd
index c001d65..ae4d3e2 100644
--- a/aggressive-murja.asd
+++ b/aggressive-murja.asd
@@ -82,7 +82,10 @@
 				 (:file "tabs")
 				 (:file "blogpost")))
 		   (:module "admin"
-		    :components ((:file "post-list")))
+		    :components ((:module "components"
+				  :components ((:file "editor")))
+				 (:file "post-list")
+				 (:file "new-post")))
 		   (:file "blog-root")
 		   (:file "single-post")))
 		 (:file "main"))))
diff --git a/resources/css/murja.css b/resources/css/murja.css
index 3ff46d7..c865f6a 100644
--- a/resources/css/murja.css
+++ b/resources/css/murja.css
@@ -37,7 +37,7 @@ html, body {
     display: block;
     position: absolute;
     height: 100%;
-    width: 80%;
+    width: 70%;
 }
 
 #editor-buttons * {
diff --git a/src/middleware/auth.lisp b/src/middleware/auth.lisp
index 303c603..d5696dc 100644
--- a/src/middleware/auth.lisp
+++ b/src/middleware/auth.lisp
@@ -1,5 +1,5 @@
 (defpackage murja.middleware.auth
-  (:use :cl :postmodern)
+  (:use :cl :postmodern :murja.users.user-db)
   (:import-from :murja.model.user :user-username)
   (:export :@ssr-authenticated :*now* :*session-key* :*user* :@can?))
 
diff --git a/src/model/post.lisp b/src/model/post.lisp
index 06edc01..9ad4021 100644
--- a/src/model/post.lisp
+++ b/src/model/post.lisp
@@ -10,15 +10,15 @@
 ;; fuck it we're moving from hashmaps to clos now 
 (defclass Post ()
   ;; slots are copied from the table blog.Post, accessors are what I might call these were I designing the db nowadays 
-  ((id :initarg :id :accessor post-id :col-type integer)
-   (title :initarg :title :accessor post-title :col-type string)
-   (content :initarg :content :accessor article :col-type string)
+  ((id :initarg :id :accessor post-id :initform nil :col-type integer)
+   (title :initarg :title :accessor post-title :initform "" :col-type string)
+   (content :initarg :content :accessor article :initform "" :col-type string)
    (creator :initarg :creator :initform nil :accessor creator)
-   (creator-id :initarg :creator-id :col-type string :reader creator-id :col-references (murja.model.user:user 'murja.model.user::id))
-   (tags :initarg :tags :accessor tags :col-type string)
-   (created-at :initarg :created-at :accessor created-at :col-type simple-date:timestamp)
-   (hidden :initarg :hidden? :accessor post-hidden? :col-type boolean)
-   (unlisted :initarg :unlisted? :accessor post-unlisted? :col-type boolean)
+   (creator-id :initarg :creator-id :initform nil :col-type string :reader creator-id :col-references (murja.model.user:user 'murja.model.user::id))
+   (tags :initarg :tags :accessor tags :col-type string :initform nil)
+   (created-at :initarg :created-at :accessor created-at :initform nil :col-type simple-date:timestamp)
+   (hidden :initarg :hidden? :accessor post-hidden? :initform t :col-type boolean)
+   (unlisted :initarg :unlisted? :accessor post-unlisted? :initform nil :col-type boolean)
    (previous :ghost t :initarg :previous :accessor previous-post-id :col-type integer :initform -1)
    (next :initform -1 :ghost t :initarg :next :accessor next-post-id :col-type integer)
 
diff --git a/src/view/admin/components/editor.lisp b/src/view/admin/components/editor.lisp
new file mode 100644
index 0000000..042dc7f
--- /dev/null
+++ b/src/view/admin/components/editor.lisp
@@ -0,0 +1,34 @@
+(defpackage murja.view.admin.components.editor
+  (:use :cl :binding-arrows :spinneret)
+  (:export :editor)
+  (:import-from :murja.model.post :article :post-title :post-hidden? :post-unlisted?))
+
+(in-package :murja.view.admin.components.editor)
+
+(defun header (post)
+  (with-html
+    (:label "Title: "
+	    (:input :id "title" :name "title" :value (post-title post) :type "text"))
+    (:label "Hidden: "
+	    (:input :id "hidden" :name "hidden" :checked (post-hidden? post) :type "checkbox"))
+    (:label "Unlisted: "
+	    (:input :id "unlisted" :name "unlisted" :checked (post-unlisted? post) :type "checkbox"))))
+
+(defun editor (post)
+  (with-html
+    ;; TODO: throw this into parenscript?
+    (:script (:raw
+	      (format nil "
+document.addEventListener('DOMContentLoaded', _ => {
+    var editor = ace.edit('editor-post-content',
+{theme: 'ace/theme/monokai',
+ mode: 'ace/mode/html'});
+
+    editor.setKeyboardHandler('ace/keyboard/emacs');
+
+    editor.setValue(~s);
+});" (article post))))
+
+    (header post)
+    (:div 
+     (:div :id "editor-post-content"))))
diff --git a/src/view/admin/new-post.lisp b/src/view/admin/new-post.lisp
new file mode 100644
index 0000000..483afb8
--- /dev/null
+++ b/src/view/admin/new-post.lisp
@@ -0,0 +1,23 @@
+(defpackage murja.view.admin.new-post
+  (:use :cl :binding-arrows :spinneret :murja.model.post :murja.view.admin.components.editor)
+  ;; (:import-from :murja.model.post :article :post-title)
+  (:import-from :murja.view.components.tabs :deftab))
+
+(in-package :murja.view.admin.new-post)
+
+(defun head-script ()
+  (with-html
+    (:script
+     :src "https://cdnjs.cloudflare.com/ajax/libs/ace/1.43.3/ace.min.js"
+     :integrity "sha512-BHJlu9vUXVrcxhRwbBdNv3uTsbscp8pp3LJ5z/sw9nBJUegkNlkcZnvODRgynJWhXMCsVUGZlFuzTrr5I2X3sQ=="
+     :crossorigin "anonymous"
+     ;; :referrerpolicy "no-referrer"
+     )))
+
+(deftab blog/new-post (:url "/blog/new-post"
+		       :subtab murja.view.admin.post-list:blog/postadmin
+		       :require-login t
+		       :needed-abilities ("create-post" "delete-post" "edit-post")
+		       :inject-to-head (#'head-script))
+  (let ((new-post (make-instance 'post :content "kissa" :title "titteli")))
+    (editor new-post)))
diff --git a/src/view/admin/post-list.lisp b/src/view/admin/post-list.lisp
index 84e387a..b4eea9e 100644
--- a/src/view/admin/post-list.lisp
+++ b/src/view/admin/post-list.lisp
@@ -4,7 +4,8 @@
    :murja.settings :cl-hash-util
    :murja.view.components.blogpost)
   (:import-from :murja.view.components.tabs :deftab)
-  (:import-from :murja.model.post :admin-get-all-titles :title :month :year :id :tags :hidden :unlisted))
+  (:import-from :murja.model.post :admin-get-all-titles :title :month :year :id :tags :hidden :unlisted)
+  (:export :blog/postadmin))
 
 (in-package :murja.view.admin.post-list)
 
diff --git a/src/view/components/root.lisp b/src/view/components/root.lisp
index f31673f..d7d67ef 100644
--- a/src/view/components/root.lisp
+++ b/src/view/components/root.lisp
@@ -33,6 +33,13 @@
 								       Title))))
 							  (gethash month by-month)))))))))))))))
 
+(defun sidebar/new-post ()  
+  (with-html
+    (if (and *user*
+	     (not (equalp "/blog/new-post" (hunchentoot:request-uri*))))
+	(:a :href "/blog/new-post" "NEW POST"))))
+	
+
 (defun loginform/user-widget ()
   (with-html 
     (if *user*
@@ -70,6 +77,7 @@
 		 (:div :class "sidebar-flex"
 		       ,inner-component
 		       (:div :id "sidebar"
+			     (sidebar/new-post)
 			     (loginform/user-widget)
 			     (sidebar-tree)
 			     (if *inject-to-sidebar*
diff --git a/src/view/components/tabs.lisp b/src/view/components/tabs.lisp
index 4ceb123..256ad60 100644
--- a/src/view/components/tabs.lisp
+++ b/src/view/components/tabs.lisp
@@ -44,7 +44,7 @@
 	   (make-instance 'tab :url ,url
 			       :abilities (list ,@needed-abilities)
 			       :require-login ,require-login
-			       :subtab ,subtab
+			       :subtab (quote ,subtab)
 			       :title ,title
 			       :component (lambda (&rest all)
 					    (destructuring-bind ,captured-url-params all 
@@ -72,11 +72,14 @@
     (:div.tabs :id "topbar"
 	       (:ul.tab-headers
 		(dolist (tab tablist)
-		  (:li :class (format nil "tab-header ~a" (when (equalp tab selected-tab) "tab-selected"))
-		       ;; wonder if this is actually necessary or just an artifact of the old newui branch?
-		       :data-href (tab-url tab)
-		       (:a :href (tab-url tab)
-			   (title tab)))))
+		  (unless (subtab tab)
+		    (:li :class (format nil "tab-header ~a" (if (equalp tab selected-tab)
+								"tab-selected"
+								""))
+			 ;; wonder if this is actually necessary or just an artifact of the old newui branch?
+			 :data-href (tab-url tab)
+			 (:a :href (tab-url tab)
+			     (title tab))))))
 	       (apply (tab-component selected-tab) tab-parameters))))