diff --git a/app.py b/app.py index a56ce33..6594536 100644 --- a/app.py +++ b/app.py @@ -157,10 +157,19 @@ def trending(): """ Explore page. """ + projects = dazzle.get_trending_projects() if filter := request.args.get("filter"): return render_template("trending.html", filter=filter) - return render_template("trending.html") + return stream_template("trending.html") +@app.get("/api/trending/") +def get_trending(): + """ + Gets trending projects and returns them as json + + Requires a `page` argument in url + """ + return dazzle.get_trending_projects(40, int(request.args.get("page"))) @app.get("/forums") def categories(): diff --git a/dazzle.py b/dazzle.py index 77d4f79..4e6daec 100644 --- a/dazzle.py +++ b/dazzle.py @@ -232,24 +232,6 @@ def get_topic_data(topic_id) -> dict: except requests.exceptions.JSONDecodeError: return {"error": True, "message": "lib_scratchdbdown"} - -@lru_cache(maxsize=15) -def get_trending_projects() -> dict: - """ - Gets trending projects from the Scratch API. - - Returns: - - dict: Trending projects. - """ - # TODO: implement limits and offsets - # language parameter seems to be ineffectual when set to another lang - r = requests.get( - "https://api.scratch.mit.edu/explore/projects?limit=20&language=en&mode=trending&q=*", - timeout=10, - ) - return r.json() - - def get_topic_posts(topic_id, page=0, order="oldest") -> dict: """ Gets posts for a topic. @@ -397,6 +379,22 @@ def get_studio_data(id) -> dict: def get_studio_comments(id): pass +def get_trending_projects(limit: int = 20, page: int = 1): + """ + Gets a list of trending projects for the explore page + + - `page` (int): The page of results + + Returns: + - list: Projects + """ + offset = limit * (page - 1) + r = requests.get( + f"https://api.scratch.mit.edu/search/projects?q=*&mode=trending&language=en&limit={limit}&offset={offset}", + timeout=10 + ) + return r.json() + # Below this line is all stuff used for the REPL debugging mode # Generally, don't touch this, unless there's a severe flaw or something diff --git a/static/master-styles.css b/static/master-styles.css index 731ee8e..9423368 100644 --- a/static/master-styles.css +++ b/static/master-styles.css @@ -479,4 +479,29 @@ textarea { body { margin: 0px; +} + +#load { + display: flex; + align-items: center; + justify-content: center; + width: 130px; + min-height: 70px; + max-height: 180px; + margin: 13px; +} + +#loadMoreButton { + width: 150px; + height: 100px; + font-size: larger; + font-weight: bold; +} + +.title, +.author { + overflow: hidden; + display: block; + text-overflow: ellipsis; + white-space: nowrap; } \ No newline at end of file diff --git a/templates/trending.html b/templates/trending.html index e647e53..f571a10 100644 --- a/templates/trending.html +++ b/templates/trending.html @@ -4,7 +4,8 @@

Explore

Find cool projects

-

This is not functional yet. What you see here is a mockup. We are working on it and will release it as fast as we can

+

Filters are not functional yet. What you see here is a mockup. We are working on it and will release it as fast + as we can

@@ -33,13 +34,41 @@

Explore

- {% for project in range(50) %} -
- pizza -
pizza recipe by coolgamer69420
- 1 view -
- {% endfor %} +
-{% endblock %} \ No newline at end of file + + +{% endblock %} + + + \ No newline at end of file