diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index 142d7ce1..6fe53515 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -60,3 +60,27 @@ class ApplicationSettingsForm(forms.Form): downloads_add_thumbnail = forms.ChoiceField( widget=forms.Select, choices=THUMBNAIL_CHOICES, required=False ) + + +class VideoSearchForm(forms.Form): + """search videos form""" + + searchInput = forms.CharField( + label="Search your videos", + widget=forms.TextInput(attrs={"autocomplete": "off"}), + ) + + +class ChannelSearchForm(forms.Form): + """search for channels""" + + searchInput = forms.CharField( + label="", + widget=forms.TextInput( + attrs={ + "oninput": "searchChannels(this.value)", + "autocomplete": "off", + "list": "resultBox", + } + ), + ) diff --git a/tubearchivist/home/templates/home/channel.html b/tubearchivist/home/templates/home/channel.html index 4e1102ba..10141c9a 100644 --- a/tubearchivist/home/templates/home/channel.html +++ b/tubearchivist/home/templates/home/channel.html @@ -20,11 +20,12 @@
search-icon -

Search Channels

+

Search your Channels

diff --git a/tubearchivist/home/templates/home/home.html b/tubearchivist/home/templates/home/home.html index 5f32a20c..3dd734de 100644 --- a/tubearchivist/home/templates/home/home.html +++ b/tubearchivist/home/templates/home/home.html @@ -34,7 +34,7 @@
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index faa87204..5722483c 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -17,8 +17,10 @@ from django.utils.http import urlencode from django.views import View from home.forms import ( ApplicationSettingsForm, + ChannelSearchForm, CustomAuthForm, UserSettingsForm, + VideoSearchForm, ) from home.src.config import AppConfig from home.src.download import ChannelSubscription, PendingList @@ -75,7 +77,10 @@ class HomeView(View): videos_hits = search.get_data() max_hits = search.max_hits pagination_handler.validate(max_hits) + + search_form = VideoSearchForm() context = { + "search_form": search_form, "videos": videos_hits, "pagination": pagination_handler.pagination, "sort_by": view_config["sort_by"], @@ -157,10 +162,14 @@ class HomeView(View): @staticmethod def post(request): """handle post from search form""" - post_data = dict(request.POST) - search_query = post_data["videoSearch"][0] - search_url = "/?" + urlencode({"search": search_query}) - return redirect(search_url, permanent=True) + search_form = VideoSearchForm(data=request.POST) + if search_form.is_valid(): + search_query = request.POST.get("searchInput") + print(search_query) + search_url = "/?" + urlencode({"search": search_query}) + return redirect(search_url, permanent=True) + + return redirect("home") class LoginView(View): @@ -469,7 +478,9 @@ class ChannelView(View): channel_hits = search.get_data() max_hits = search.max_hits pagination_handler.validate(search.max_hits) + search_form = ChannelSearchForm() context = { + "search_form": search_form, "channels": channel_hits, "max_hits": max_hits, "pagination": pagination_handler.pagination, diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index f03b21f4..46bd043f 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -62,7 +62,7 @@ ul { margin-left: 20px; } -td, span { +td, span, label { font-family: Sen-Regular, sans-serif; color: var(--main-font); } diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 2c8061be..27528539 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -372,7 +372,7 @@ function showSearch() { } else { searchBox.style.display = ""; } - var inputBox = document.getElementById('searchInput'); + var inputBox = document.getElementById('id_searchInput'); inputBox.focus(); }