Adds getting started find books view

This commit is contained in:
Mouse Reeve 2021-03-31 13:56:26 -07:00
parent ca14d1789d
commit 7483cb5919
5 changed files with 140 additions and 0 deletions

View file

@ -21,6 +21,10 @@ html {
overflow-x: auto;
}
.modal-card.is-fullwidth {
min-width: 75% !important;
}
/* --- SHELVING --- */
/** @todo Replace icons with SVG symbols.

View file

@ -0,0 +1,98 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
{% block title %}{% trans "Welcome" %}{% endblock %}
{% block content %}
{% with site_name=site.name %}
<div class="modal is-active" role="dialog" aria-modal="true">
<div class="modal-background"></div>
<div class="modal-card is-fullwidth">
<header class="modal-card-head">
<h1 class="modal-card-title">
{% trans "Getting Started" %}
</h1>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
<div class="block">
<h2 class="title is-4">{% trans "What are you reading?" %}</h2>
<form class="field has-addons" method="get" action="{% url 'get-started' %}">
<div class="control">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a book' %}" aria-lable="{% trans 'Search for a book' %}">
{% if request.GET.query and not book_results %}
<p class="help">{% blocktrans %}Sorry, books were found. You can add books when you start using {{ site_name }}{% endblocktrans %}</p>
{% endif %}
</div>
<div class="control">
<button class="button" type="submit">
<span class="icon icon-search" title="{% trans 'Search' %}">
<span class="is-sr-only">{% trans "Search" %}</span>
</span>
</button>
</div>
</form>
</div>
<form class="block">
<h3 class="title is-5">{% trans "Suggested Books" %}</h3>
<div class="columns scroll-x">
{% if book_results %}
<div class="column is-narrow content">
<p class="help mb-0">Search results</p>
<div class="columns">
{% for book in book_results %}
<div class="column is-narrow is-clipped">
{% include 'snippets/book_cover.html' with book=book %}
<div class="select is-small">
<select>
<option>-</option>
{% for shelf in request.user.shelf_set.all %}
<option>{{ shelf.name }}</option>
{% endfor %}
</select>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<div class="column is-narrow content">
<p class="help mb-0">
{% blocktrans %}Popular on {{ site_name }}{% endblocktrans %}
</p>
<div class="columns">
{% for book in popular_books %}
<div class="column is-narrow is-clipped">
{% include 'snippets/book_cover.html' with book=book %}
<div class="select is-small">
<select>
<option>-</option>
{% for shelf in request.user.shelf_set.all %}
<option>{{ shelf.name }}</option>
{% endfor %}
</select>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
</form>
</section>
<footer class="modal-card-foot is-flex is-justify-content-flex-end">
<button class="button">
<span>{% trans "Skip this step" %}</span>
<span class="icon icon-arrow-right" aria-hidden="true"></span>
</button>
</footer>
</div>
<a href="/" class="modal-close is-large" aria-label="close"></a>
</div>
{% endwith %}
{% endblock %}

View file

@ -109,6 +109,8 @@ urlpatterns = [
re_path(r"^discover/?$", views.Discover.as_view()),
re_path(r"^notifications/?$", views.Notifications.as_view()),
re_path(r"^directory/?", views.Directory.as_view(), name="directory"),
# Get started
re_path(r"^get-started/?$", views.GetStarted.as_view(), name="get-started"),
# feeds
re_path(r"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()),
re_path(

View file

@ -9,6 +9,7 @@ from .federation import Federation, FederatedServer
from .feed import DirectMessage, Feed, Replies, Status
from .follow import follow, unfollow
from .follow import accept_follow_request, delete_follow_request
from .get_started import GetStarted
from .goal import Goal, hide_goal
from .import_data import Import, ImportStatus
from .inbox import Inbox

View file

@ -0,0 +1,35 @@
""" Helping new users figure out the lay of the land """
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import models
from bookwyrm.connectors import connector_manager
# pylint: disable= no-self-use
@method_decorator(login_required, name="dispatch")
class GetStarted(View):
""" a book! this is the stuff """
def get(self, request):
""" info about a book """
query = request.GET.get('query')
book_results = []
if query:
book_results = connector_manager.local_search(query, raw=True)[:5]
if len(book_results) < 5:
popular_books = models.Edition.objects.exclude(
parent_work__in=[b.parent_work for b in book_results],
).annotate(
Count("shelfbook")
).order_by("-shelfbook__count")[: 5 - len(book_results)]
data = {
"book_results": book_results,
"popular_books": popular_books,
}
return TemplateResponse(request, "get_started/books.html", data)