ThomasTJdev / nim_websitecreator

Nim fullstack website framework - deploy a website within minutes
https://nimwc.org
MIT License
176 stars 7 forks source link

Redirect with Delay #78

Closed juancarlospaco closed 5 years ago

juancarlospaco commented 5 years ago

nmwc-delayredirect

Before:

get "/someurl":
  createTFD()
  if sucessful:
    redirect "/settings"

get "/reallySlowOperation":
  createTFD()
  if sucessful:
    redirect "/"

After:

get "/someurl":
  createTFD()
  if sucessful:
    resp genMain(c, genDelayRedirect("/settings", "**Nim world domination succesfull:** Returning to Settings page."))

get "/reallySlowOperation":
  createTFD()
  if sucessful:
    resp genMain(c, genDelayRedirect("/", "**Please Wait:** *Solving the squaring of the circle.*", 30))  # We know operation takes less than 30 seconds to complete.

Code to Test it, add on routes.nim:

  get "/delayredirect":
    createTFD()
    resp genMain(c, genDelayRedirect("/settings", message="**Your Message** *here*", 2))

Easy to Merge, since not touching any pre-existent code. :slightly_smiling_face:

ThomasTJdev commented 5 years ago

Really good solution! I have been trying to solve this multiple times, specially using Jester's after "/": to avoid websockets, but without success. We should only use it for actions, where we know a delay time could occur, not just for a notification like Settings has been updated. I'm looking forward to using it on the enable/disable plugins.

I can first test it on one of the next days, but the code looks fine to me, so if you need it, you can merge!