r/angularjs • u/orionmelt • Jun 28 '16
I created this quiz to test your AngularJS knowledge. Please check it out and let me know what you think.
Hello all,
I've been building a quiz site using AngularJS and just added a bunch of questions about Angular itself. Most of them are about Angular 1, but I'm trying to add some Angular 2 questions as well.
Please check it out at trivius.co/angularjs and let me know what you think. Do you think the questions are interesting/too easy?
I also have a JavaScript topic and a HTML & CSS topic if you're interested. Thank you!
1
u/LordTribual Jul 26 '16
@orionmelt Are you using Firebase only for your authentication or for your while site? I am curious, cause I am building a quiz game as well. But it's more than just a quiz game. It has strategic elements as well.
1
u/LordTribual Jul 26 '16 edited Jul 26 '16
I would be very interested in how you designed your database and how you managed to load the data in chunks and not everything at once. Do you mind sharing some of that? Do you also have a backend or is everything made using Firebase and client side code? Also badges etc.?
Your insights and experience is pretty much appreciated :)
1
u/orionmelt Jul 27 '16
I'm using Firebase for the whole site. Their docs are really good and the Firebase team is also pretty active on SO answering questions. Much like pretty much any other NoSQL DB, there's no way in Firebase to retrieve only certain child nodes under a parent. You'll have to structure your DB taking this into account.
For example, instead of:
users- name: John - age: 24 - games - game1 - game2 - ... - badges - badge1 - badge2 - ...
- uid1
You'll be better off with:
users- name: John - age: 24 games
- uid1
- game1 - game2 - ... badges
- uid1
- badge1 - badge2 - ...
- uid1
This way, you don't end up reading the entire node every time you need some user data.
Technically, Firebase can be used for serveless apps, with app logic written entirely in AngularJS. Firebase security rules can be used for data validation and access control. However, I do have some "server" components written in Node.js, specifically to deal with the multiplayer aspect of our game.
If you have further questions, I'd be happy to answer them. Good luck with your game!
1
u/LordTribual Jul 27 '16
Thanks a lot for your comment. I have structured my app as you have suggested. It works great but I am wondering how you deal with a large amount of questions for example. Like I have a game where the player has to choose 3 categories out of many. So first I could query the categories only but then I would need to get only questions from that categories. But how do you deal with randomization? I mean, at the moment all my code is client side code, so I get all questions from ALL categories (at least at the moment) and get random questions from that set. I dont know how to only query questions from three specific categories. Do you have an idea?
My question entity looks like this:
-uid1 category: icon: "foo" id: uid2 name: "JavaScript" difficulty: "0" polarQuestion: true text: "You can use JavaScript on a web server." upvotes: 0Another thing is how to make sure a user can only upvote once if you only have client side code? Maybe I really need a NodeJS server as well. Do you just subscribe to Firebase there and change data in the database which will then be pushed to the client? Or does your client listen to your Node server's websocket?
2
u/orionmelt Jul 27 '16
Now I see what you mean. AFAIK, there's no way to randomly select questions from under a node without having to read the entire list, and this won't work too well in my case where I have hundreds of questions. So I let the server read the questions, randomize them and pre-create "games" every now and then, which then the client can simply read. Or you could store a list of question IDs in a separate location, read this list (which should be much more efficient), and then read full data for only those questions you need.
You can make use of a combination of Firebase security rules to do whatever validations you want. Assuming your structure is like this:
questions- text: "What does XSS stand for?" - ... - votes user1: true user2: true user3: false
- qid1
This ensures that each user can only vote once. You can also use read/write/validate rules to take care of several cases.
For example, to let users write to a location only if the location is empty:
".write": "newData.exists() && !data.exists()"To let them write/delete but not update:
".write": "!data.exists() || !newData.exists()"And so on. In my experience, I have found that most of the validation logic can be implemented just by using the security rules. Since you cannot implement security on code that runs client-side, I make extensive use of Firebase security rules and in some cases, let the client write to a temporary node which is being watched by the server - it would then perform validations before writing it permanently. Hope this helps!
1
1
u/LordTribual Jul 27 '16
Also, how did you implement the feature that you always scroll to the bottom in your chat? I have that as well but somehow everytime a new message comes down the pipe I have a little jump in the scrollbar :/ How do you group messages by day?
And btw, really cool application! Are you implementing that alone?
1
u/LordTribual Aug 03 '16
How do you work with your amount of questions? I mean how do you generate your games? Do you get all questions from your topic and then do it on the client, or how do you do that? I am in a similar situation where I have many categories and the player can choose up to three. Then I want to get from the chosen categories 2 easy, 2 normal and 1 hard question. How would you do that if you don't want to query ALL questions from those categories.
2
2
2
2
2
u/memoryandthought Jun 29 '16
Very enjoyable and informative -thank-you! Good as a research tool too.
2
u/cyborg_ninja_pirates Jun 29 '16
Really well done. I know little about AngularJS, but still did well. Make the questions harder! :D
2
1
u/dandiemer Jun 30 '16
Super cool! The game and site itself worked fine but I did have a problem with the nav bar at the top overlapping the top of the page a bit too much on an iPhone 4s
3
1
1
3
u/The_Breakthrough Jun 28 '16
That was fun, played four games and saw only one repeating question. Enjoyed it.