debate-bro icon indicating copy to clipboard operation
debate-bro copied to clipboard

Topic repository

Open mia-z opened this issue 2 years ago • 6 comments

The main feature of this PR is adding an admin page where you can manage the topics and categories.

I decidede to make category a separate entity as I can imagine political topics can be pretty broad. As well as defining a type for the topics themselves.

A Topic is an object with 2 keys:

  • name: string
  • category: TopicCategory

A TopicCategory is just a string (originally it was a union type of predefined strings, but setting those union type values up from a db would be tedious as shit and would only affect development.. marginally.. if at all).

Navigating to the /admin page displays a small login window where you can use the username "admin" and a password defined in the env vars with the key of ADMIN_PAGE_PASSWORD. If used in production it would ideally be a bit more secure and maintainable.

After successfully logging in, you get 2 boxes: one with categories, and the other with topics - on the left and right, respectively. You can hit the Add ** button to reveal an input where you can enter the value you desire. Hit save on the right-side of the input to save the value. Creating a new topic requires you to also provide a category from the dropdown between the input field and the save button. None of these forms are validated on the frontend yet, so keep that in mind when testing.

The Topic and TopicCategory data is stored in a redis db on heroku. The I can dm the connection string I used, it's up and it's free anyway. The string is taken the the env var key REDIS_URL. Both of these are stored inside their own list with the respective keys:

  • debatebro:categories
  • debatebro:topics However since Topic is an object it must be properly parsed when it/they is/are retrieved.

I added some server-side helper methods to communicate with the redisdb, as well as the admin authentication. The helper methods (/api/redis/{type}) come with basic crud functionality in mind, however only create and read are available at this time.

Finally, I added typescript to the project, but strict mode is off so you shouldn't have to worry about it interfering if it's something you unfamiliar with.

mia-z avatar Aug 02 '22 19:08 mia-z

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
debate-bro ❌ Failed (Inspect) Sep 2, 2022 at 7:26PM (UTC)

vercel[bot] avatar Aug 02 '22 19:08 vercel[bot]

Hey! Thank you for contributing, trying to check out your work but ran into some trouble

Redis error
Error: connect ECONNREFUSED 127.0.0.1:6379

I suppose I should have the redis server running locally?

ceselder avatar Aug 02 '22 19:08 ceselder

also a current bug you should know about, the UseLocalStorage hook is not updating the topics correctly if the topics change server side, will fix soon

ceselder avatar Aug 02 '22 20:08 ceselder

Thats correct, yeah. I used one on heroku myself, but local is fine too. Just be sure to set the env var REDIS_URL to your redis url.

It doesnt use the new data on the index page yet, thats something I can sort out next, though.

mia-z avatar Aug 02 '22 20:08 mia-z

I never really intended to maintain this project since I suspected hype would quickly die down. Your contribution however is pretty nice.

Typescript is something that I have been kicking down the road for ages so I should probably use it, including it in the project is nice.

I am as unfamiliar with redis as one can be and have only used mongodb and traditional SQL databases, I will review the code regardless and am not opposed to its usage. Re-reading your post now and it just clicked that u totally mentioned that redis is remotely hosted, could you quickly dm the details?

I dont quite understand what the value would be of splitting up topics in name and categories

As you alluded to in your comment, the auth system could definitely use some work before being incorporated into production.

This is my first pull request so I would like to thank you again for your contribution :+1:

ceselder avatar Aug 02 '22 20:08 ceselder

So the idea of having Categories was to be able to make the main topic box (The one titled "Available Topics") a tabbed box that was tabbed with the categories and only the topics related to that category would appear under it. See react-tabs for an idea of what I mean. It wasn't something I could implement right now as it would mean rewriting your component for droppable/draggable system which I havent properly looked at yet and looked like a more tedious task that I anticipated. Might still implement it tomorrow.

mia-z avatar Aug 02 '22 23:08 mia-z