add search results page

This commit is contained in:
Joe Ardent 2023-06-14 22:11:43 -07:00
parent 5f02fb265a
commit 1540153b67
3 changed files with 43 additions and 7 deletions

View File

@ -1,5 +1,3 @@
use std::path::Path;
use axum::{
extract::{Form, Query, State},
http::StatusCode,
@ -9,6 +7,7 @@ use serde::Deserialize;
use sqlx::{query_as, SqlitePool};
use uuid::Uuid;
use super::templates::GetSearchWatches;
use crate::{AuthContext, GetWatches, ShowKind, User, Watch};
//-************************************************************************
@ -79,15 +78,21 @@ pub async fn get_watches(auth: AuthContext, State(pool): State<SqlitePool>) -> i
}
pub async fn get_search_watch(
_auth: AuthContext,
State(pool): State<SqlitePool>,
auth: AuthContext,
State(_pool): State<SqlitePool>,
search: Option<Query<SimpleSearchQuery>>,
) {
) -> impl IntoResponse {
let search = match search {
Some(Query(SimpleSearchQuery { search })) => search,
None => "".to_owned(),
};
let search = search.trim();
let search = search.trim().to_string();
let user = auth.current_user;
GetSearchWatches {
watches: vec![],
user,
search,
}
}
pub async fn post_search_watch() {}

View File

@ -12,4 +12,8 @@ pub struct GetWatches {
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
#[template(path = "get_search_watches.html")]
pub struct GetSearchWatches {}
pub struct GetSearchWatches {
pub watches: Vec<Watch>,
pub user: Option<User>,
pub search: String,
}

View File

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% import "macros.html" as m %}
{% block title %}Welcome to Witch Watch, Bish{% endblock %}
{% block content %}
<h1>Whatcha Watchin?</h1>
<div class="quicksearch-query">{{self.search}}</div>
<div class="watchlist">
<ul>
{% for watch in watches %}
<li><span class="watchtitle">{{watch.title}}</span> -- {% call m::get_or_default(watch.release_date, "when??") %}: </li>
{% endfor %}
</ul>
</div>
<p>
<form action="/search" enctype="application/x-www-form-urlencoded" method="get">
<label for="search">Looking for something else to watch?</label>
<input type="text" name="search" id="search"></br>
<input type="submit" value="Let's go!">
</form>
</p>
{% endblock %}