Coder Social home page Coder Social logo

flash's Issues

It doesn't work

The Flash package doesn't seem to work.

Following the documentation, double checking the configuration and requirements. I even created a new project just to configure flash and have one route that does nothing but redirect to the next one whilst adding a flash message.

configure.swift

import Leaf
import Vapor
import Flash

/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
  /// Register providers first
  try services.register(LeafProvider())
  try services.register(FlashProvider())

  /// Register routes to the router
  let router = EngineRouter.default()
  try routes(router)
  services.register(router, as: Router.self)
    
  /// Use Leaf for rendering views
  config.prefer(LeafRenderer.self, for: ViewRenderer.self)

  /// Register middleware
  var middlewares = MiddlewareConfig() // Create _empty_ middleware config
  middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
  middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
  middlewares.use(SessionsMiddleware.self)
  middlewares.use(FlashMiddleware.self)
  services.register(middlewares)
}

routes.swift

import Vapor
import Flash

public func routes(_ router: Router) throws {
  router.get { req in
    return try req.view().render("welcome")
  }

  router.get("hello") { req -> Future<Response> in
    return req.future(req.redirect(to: "/").flash(.error, "Hey Listen!"))
  }
}

welcome.leaf

#set("title") { It works }

#set("body") {
  <div class="welcome">
    <div class="alerts">
      #flash() {
        #for(flash in all) {
          Message: #(flash.message)
          Type: #(flash.kind)
        }
      }
    </div>
    <img src="/images/it-works.png">
  </div>
}

#embed("base")

Putting a breakpoint in the package at the check whether flashes isEmpty shows, it is empty.. 🤔

Show flash messages only once

My impression of flash messages would be to show them only once. In this implementation, I see them only get added but not removed. Am I doing something wrong or am I missing something?

Otherwise, my suggestion would be to remove them when being rendered, so to insert the following line into FlashTag.swift at the end of the function render:

flash.flashes.removeAll()

Folder structure

Sort out folder structure (align with other packages) and split code into files when needed.

Vapor Error causing not to Compile

Vapor requires a release 4.0.1 to solve dependencies properly. I forked, published the release, and it works fine.

Please just release 4.0.1 so that it will compile properly.

Thanks

About uses both flash tag and custom tag

The following codes won't work, the error message is No tag named `x` is registered.

services.register { container -> LeafTagConfig in
        var leafTagConfig = LeafTagConfig.default()
        leafTagConfig.use(XLeafTagRenderer(), as: "x")
        leafTagConfig.use(FlashTag(), as: "flash")
        return leafTagConfig
}

try services.register(FlashProvider())

The following codes won't work, the error message is No tag named `flash` is registered.

services.register { container -> LeafTagConfig in
        var leafTagConfig = LeafTagConfig.default()
        leafTagConfig.use(XLeafTagRenderer(), as: "x")
        return leafTagConfig
}

try services.register(FlashProvider())

The following codes will work.

try services.register(FlashProvider())

services.register { container -> LeafTagConfig in
        var leafTagConfig = LeafTagConfig.default()
        leafTagConfig.use(XLeafTagRenderer(), as: "x")
        leafTagConfig.use(FlashTag(), as: "flash")
        return leafTagConfig
}

So, I think there is no point in importing MutableLeafTagConfig

Can't seem to get it working.

Hey so I followed all of the instructions. I'm trying to add this globally. No matter what I do I can't seem to get the flash messages to render in my HTML. I copied and pasted the code from the README. Is there a way I can debug what is going on? I don't get any errors or anything. Thanks.

Vapor 3

Now that Vapor 3 is nearing a final release, what does the status look like for updating this library? I am more than happy to write the Vapor 3 version if someone can help point me in the right direction with request.storage not being around anymore.

Vapor 2

Now that Vapor 2 is released I'd love to see an official 1.0 tag supporting Vapor 2.

This package is awesome! I use it in all my projects. Kudos.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.