You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
💻 adventure tabs and editor in public adventures page (#4990)
Fixes#4954
# Features
Initially the page shows all available public adventures.

There are four filters that teachers can utilize in order to find adventures quickly. These filters are:
1. search input: finds an adventure whose name matches the search input
2. level (default=1): gets adventures of a specific level. Only one item can be selected.
3. language: gets adventures of a specific language. Only one item can be selected.
4. tags: gets adventures that have at least one of the selected tags. Multiple items can be selected.
Another interesting and important feature is that the URL always updates wrt the filters. For instance, if you filter by English, the URL will be something like: public-adventures?level=1&**lang=en**&tag=&search=. The same applied to all available filters. Additionally, this means that you can share a url with someone and they would see the exact same adventures you've filtered. So, if you share `/public-adventures?level=1&lang=&tag=print&search=parr` with another teacher, they will see exactly what you see:

# **How to test?**
Go to `/public-adventures` and start applying some filters, run some code of any adventure you like, and perhaps clone one that's created by some other user.
# **Technicality (for devs)**
Whenever a filter is applied, we send a request to python and expect two things:
- `html`: the template of the new filtered adventures, to replace the current adventure tabs with.
- `js`: some properties that are needed for js; e.g., to initialize the editor.
The html is simply a string that we replace the innerHTML of the target element that includes the editor and tabs. And since this is a string, we need to manually initialize the JS code; e.g., run the `initializeHighlightedCodeBlocks` or initialize the editor with the selected level.
The reason why I didn't use htmx here is due to the fact that the created template that has the editor and tabs (i.e., in `public-adventures-body.html`) does not issue a rerender on the js side. Most probably, this behavior is because htmx only replaces a target element by whatever the server returns and does not mind the `js` property that we pass to the template. As a result, the editor and tabs become just views with no interactivity.
Another matter is the usage of Tailwind Elements. I used this for two reasons: it uses Tailwind (which we also do) and it has a plenty of already styled elements. The problem with TE is that they don't support RTL currently, [however, they did mention that they're working on it](mdbootstrap/TW-Elements#2264 (comment)). So, let's just keep using our custom select that I created, until they fix that issue or we need some of the beautiful components they provide.
Copy file name to clipboardExpand all lines: data-for-testing.json
+19-1
Original file line number
Diff line number
Diff line change
@@ -1460,8 +1460,26 @@
1460
1460
"creator": "teacher1",
1461
1461
"name": "adventure1",
1462
1462
"level": "1",
1463
+
"levels": ["1", "2"],
1463
1464
"content": "This is the explanation of my adventure!\n\nThis way I can show a command: <code>print</code>\n\nBut sometimes I might want to show a piece of code, like this:\n<pre class=\"no-copy-button\">ask What's your name?\necho so your name is \n</pre>",
0 commit comments