Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings not loading from turbo.json #1

Closed
aviderambo opened this issue Jun 25, 2021 · 6 comments
Closed

Settings not loading from turbo.json #1

aviderambo opened this issue Jun 25, 2021 · 6 comments

Comments

@aviderambo
Copy link

Hey thanks for the awesome starting point for us who know nothing about Swift!

I'm not sure if this issue is related to my rails setup. I created a new project and followed the instructions from the readme.

CleanShot 2021-06-25 at 18 10 01

CleanShot 2021-06-25 at 18 13 26

@dalezak
Copy link
Owner

dalezak commented Jun 25, 2021

Hmm, your turbo.json looks fine, try changing your print lines to

print("path \(path)")
print("text \(text)")

And also add print("json \(json)") inside the if let json block, that should output the contents.

@aviderambo
Copy link
Author

aviderambo commented Jun 26, 2021

Weird, right?

CleanShot 2021-06-25 at 19 37 05

CleanShot 2021-06-25 at 20 41 51

This seems to be working. The request must be made from WK View for any reason?

    func loadSettings() -> Dictionary<String, AnyObject> {
        let path = turboPath("/turbo.json")
        let url = URL(string: path)
        let semaphore = DispatchSemaphore(value: 0)
        var text: String = ""
        
        let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
            text = String(data: data!, encoding: String.Encoding.utf8)!
            semaphore.signal()
        }
        task.resume()
        semaphore.wait()

        if let json = stringToDictionary(text: text) {
            return (json["settings"] as? Dictionary<String, AnyObject>)!
        }
        return [:]
    }

@dalezak
Copy link
Owner

dalezak commented Jun 26, 2021

Do you have @hotwired/turbo-rails in your package.json?

I just realized I forgot this in the instructions.

If you are using Yarn, do yarn add @hotwired/turbo-rails.

If you are using NPM, do npm add @hotwired/turbo-rails.

https://www.npmjs.com/package/@hotwired/turbo-rails

@dalezak
Copy link
Owner

dalezak commented Jun 26, 2021

Alright @codigodo, I tested out your changes and they seem to work well.

So I've updated loadSettings to use URLSession.shared.dataTask instead.

Can you pull the latest to verify the changes still work for you?

@aviderambo
Copy link
Author

Works great!

@dalezak
Copy link
Owner

dalezak commented Jun 26, 2021

Good news, closing issue.

@dalezak dalezak closed this as completed Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants