From 7765ce786ffd393c305c0b646ac84a88aa2c0b9c Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 30 Jul 2020 17:16:14 +0200 Subject: [PATCH] move search bar out of header, implement way to include links in headerbar --- app/invidious/__init__.py | 42 +++++++++++------- app/invidious/templates/search.html.j2 | 61 +++++++++++++++++++------- app/reddit/__init__.py | 13 +++++- app/static/style.css | 10 +++++ app/templates/base.html.j2 | 30 ++++++------- app/youtube/templates/index.html.j2 | 1 - 6 files changed, 108 insertions(+), 49 deletions(-) diff --git a/app/invidious/__init__.py b/app/invidious/__init__.py index 1c85d72..10a3d16 100644 --- a/app/invidious/__init__.py +++ b/app/invidious/__init__.py @@ -1,5 +1,5 @@ import requests -from flask import Blueprint, render_template, request, flash +from flask import Blueprint, render_template, request, flash, g, url_for from ..common.common import fallback_route @@ -30,20 +30,21 @@ def search(): for p in ['sort_by', 'date', 'duration', 'type', 'features', 'region'] } - if not q: - return "no search query", 400 - - r = requests.get(f"https://invidio.us/api/v1/search", { - 'q': q, - 'page': page, - # **optional_params, - }) - if not r.ok: - return "error fetching search results", 502 # TODO: better - - # XXX: should check r.json if it really are search results (if other provider) - # XXX: should transform invidious-json to our naming scheme - return render_template('search.html.j2', rows=r.json(), query=q, page=page, + if q: + r = requests.get(f"https://invidio.us/api/v1/search", { + 'q': q, + 'page': page, + # **optional_params, + }) + if not r.ok: + return "error fetching search results", 502 # TODO: better + # XXX: should check r.json if it really are search results (if other provider) + # XXX: should transform invidious-json to our naming scheme + results = r.json() + else: + results = None + + return render_template('search.html.j2', rows=results, query=q, page=page, optional_params=optional_params) @frontend.route('/channel/') @@ -88,3 +89,14 @@ def playlist(): return fallback_route() return render_template('channel.html.j2', rows=r.json().get('videos',[]), page=page) + +@frontend.before_app_request +def inject_search_button(): + if not 'header_items' in g: + g.header_items = [] + g.header_items.append({ + 'name': 'search', + 'url': url_for('invidious.search'), + 'parent': frontend.name, + 'priority': 10, + }) diff --git a/app/invidious/templates/search.html.j2 b/app/invidious/templates/search.html.j2 index 70eabd4..6b5bbf0 100644 --- a/app/invidious/templates/search.html.j2 +++ b/app/invidious/templates/search.html.j2 @@ -1,25 +1,56 @@ {% extends "base.html.j2" %} {% import 'macros.imp.j2' as macros %} -{% block title %}{{ query | e }} — Search results{% endblock %} +{% block title %} +{% if rows is not none %}{{ query | e }} — Search results +{% else %}Search Youtube Videos{% endif %} +{% endblock %} {% block content %} -{{ super() }} -
-{% for row in rows %} - {% call macros.card(row.videoId, row.title, row.publishedText) %} - {{ macros.infobar_subscriptions(row.videoId, row.authorId, row.author) }} - {% endcall %} -{% else %} - no more results. -{% endfor %} -{{ macros.dummycard() }} -
+ +
+ + + +
-{% if page > 1 %} -previous | +{% if rows is not none %} + {{ super() }} +
+ {% for row in rows %} + {% call macros.card(row.videoId, row.title, row.publishedText) %} + {{ macros.infobar_subscriptions(row.videoId, row.authorId, row.author) }} + {% endcall %} + {% else %} + no more results. + {% endfor %} + {{ macros.dummycard() }} +
+ + {% if page > 1 %} + previous | + {% endif %} + next +{% else %} + please type a search query. {% endif %} -next {% endblock %} {% block footer %} diff --git a/app/reddit/__init__.py b/app/reddit/__init__.py index 4ffa7c3..80989db 100644 --- a/app/reddit/__init__.py +++ b/app/reddit/__init__.py @@ -1,7 +1,7 @@ import re import sqlite3 from flask_login import current_user, login_required -from flask import Blueprint, render_template, request, redirect, flash +from flask import Blueprint, render_template, request, redirect, flash, url_for from ..common.common import * from .lib import * @@ -122,3 +122,14 @@ def trim3(n): return "%.1fk" % (n/1000) else: return "%d" % n + +@frontend.before_app_request +def inject_reddit_button(): + if not 'header_items' in g: + g.header_items = [] + g.header_items.append({ + 'name': 'reddit', + 'url': url_for('reddit.reddit'), + 'parent': frontend.name, + 'priority': 5 + }) diff --git a/app/static/style.css b/app/static/style.css index b814d0b..1d6744b 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -241,3 +241,13 @@ ul#submgr{list-style: none} .emoji-form { display: inline; } + +.header-left:not(:first-of-type) { + margin-left: 1em; +} +.header-left.bold { + font-weight: bold; +} +.header-left.large { + font-size: large; +} diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index 3fa5923..5ddfe66 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -9,29 +9,25 @@ {% import 'macros.imp.j2' as macros %} {% block header %} - - - - Δ{{ request.host }} - + + {% set tag = 'b' if request.blueprint in ["youtube", "usermgmt"] else 'span' %} + + <{{tag}} class="header-left large"> + Δ{{ request.host }} + + + {% for x in g.header_items|sort(attribute="priority", reverse=true) %} + + {{ x.name }} + + {% endfor %} {% if current_user.is_anonymous %} log in or sign up {% else %} {{ current_user.name }} (log out) {% endif %} -
- - - -
-
+
{% endblock %} {% with messages = get_flashed_messages(with_categories=true) %} diff --git a/app/youtube/templates/index.html.j2 b/app/youtube/templates/index.html.j2 index 6712041..0b38d59 100644 --- a/app/youtube/templates/index.html.j2 +++ b/app/youtube/templates/index.html.j2 @@ -32,5 +32,4 @@ {% block footer %}
Manage Subscriptions - | Reddit Feed {% endblock %} -- 2.39.3