From 1a2ee6435c94185e960cb3b6fc032d38914a8caa Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 25 Aug 2022 09:07:14 -0500 Subject: [fix] auto refresh --- flexo.lisp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/flexo.lisp b/flexo.lisp index e9369c3..bff77b0 100644 --- a/flexo.lisp +++ b/flexo.lisp @@ -35,6 +35,10 @@ (defun mark-autorefresh-true (directory) (when *auto-refresh-key* + (alexandria:write-string-into-file + (auto-refresh-script-ps) + (format nil "~a/auto-refresh-script.js" directory) + :if-exists :supersede) (alexandria:write-string-into-file "true" (format nil "~a/~a.json" directory *auto-refresh-key*) @@ -42,6 +46,10 @@ (defun mark-autorefresh-false (directory) (when *auto-refresh-key* + (alexandria:write-string-into-file + (auto-refresh-script-ps) + (format nil "~a/auto-refresh-script.js" directory) + :if-exists :supersede) (alexandria:write-string-into-file "false" (format nil "~a/~a.json" directory *auto-refresh-key*) @@ -62,17 +70,20 @@ (defun auto-refresh-script () (when *auto-refresh-key* (with-html - (:script - (ps:ps - (let ((poll-url (+ "/" (ps:lisp flexo::*auto-refresh-key*) ".json"))) - (set-interval - (lambda () - (let ((fetched (fetch poll-url))) - (ps:chain fetched - (then (lambda (resp) (ps:chain resp (json)))) - (then (lambda (json) - (when json (ps:chain location (reload)))))))) - 1000))))))) + (:script :src "/auto-refresh-script.js")))) + +(defun auto-refresh-script-ps () + (ps:ps + (set-interval + (lambda () + (let ((fetched + (fetch + (ps:lisp (format nil "/~a.json" flexo::*auto-refresh-key*))))) + (ps:chain fetched + (then (lambda (resp) (ps:chain resp (json)))) + (then (lambda (json) + (when json (ps:chain location (reload)))))))) + 1000))) (defun table-subset-p (tab1 tab2 &key (test 'equal)) "TEST compares values" -- cgit v1.2.3