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.