Julia: call a function whenever route is refreshed?

Viewed 52

I have a Genie route which displays an html page. The page should display a list of html elements based on a column in a database table ( for the example, a list of friends) :

route("/") do
  html(refresh())
end

The refresh function gets the html, from the logFriend function (which uses a macro).

function refresh()
  loggingPage = logFriend()
  return loggingPage
end

This is the post (the page also has a text input and a submit). After the user submits, a dataframe is displayed, showing the contents of the updated db table.

route("/", method = POST) do
  queries.insertFriend(postpayload(:friend))
  refresh()
  ob2 = getFriends()
  return ob2
end

Below is the macro which creates the html elements based on the db column, and the function which adds it to the html.

macro htmlFriends()
    str1 = ""
    friendList = getFriends().friend
    for x in friendList
        str = "<li>$x</li>\n"
        str1 = str1 * str
    end
    return str1
end

function logFriend()
    m1 = @htmlFriends
    pa = "style='text-align:left"
    logPage = """
        <form action="/" method="POST" enctype="multipart/form-data">
        <script>
        for (let i=0; i<9;i++)
          document.write("hi");
        </script>
          <body  $pa> List of Friends
              $m1
              <div $pa>friend!
                  <input type="text" name="friend" value="" />
              </div>
              <div $pa>
                <input type="submit" value="submit" />
              </div>
          </body>
        </form>
        """
        return logPage
    end

But the list elements on the page do not update when i refresh.

Right now, if i run the logFriend function manually, and then rerun the route with the refresh function inside, it displays the proper elements. But i dont want to manually refresh, I want it to be automatic. I have tried to change refresh to a macro that can be run in the route but that isnt the issue.. Any help would be appreciated!

0 Answers
Related