Less nav buttons

This commit is contained in:
Adrian Woźniak 2022-07-25 11:39:18 +02:00
parent 65b5cabc8b
commit 3d7244320f
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B
11 changed files with 144 additions and 131 deletions

View File

@ -49,6 +49,7 @@ ow-nav > ow-path {
text-align: center;
width: 48px;
}
ow-nav > ow-path > div {
display: none;
}
@ -155,3 +156,36 @@ ow-nav > ow-path[selected="selected"] {
ow-nav > ow-path[selected="selected"] > svg {
fill: var(--hover-color);
}
.btn {
cursor: pointer;
border-radius: 5px;
box-shadow: 0 10px 20px -6px rgba(0, 0, 0, .12);
position: relative;
margin-bottom: 20px;
transition: .3s;
display: inline-block;
font-weight: 400;
text-align: center;
vertical-align: middle;
user-select: none;
font-size: 1rem;
line-height: 1.5;
transition: color .15s ease-in-out,
background-color .15s ease-in-out,
border-color .15s ease-in-out,
box-shadow .15s ease-in-out;
width: auto;
height: calc(1.5em + 0.75rem + 2px);
padding: .375rem .75rem;
border: 1px solid #495057;
color: #495057;
background: white;
}
a.btn {
text-decoration: none;
line-height: 2;
}

View File

@ -1,4 +1,4 @@
import { Component, FORM_STYLE, TIP_STYLE } from "../shared";
import { Component, FORM_STYLE, TIP_STYLE } from "../shared.js";
customElements.define('offer-form', class extends Component {
static get observedAttributes() {

View File

@ -4,20 +4,17 @@ const MODES = { 'view': 'view', 'form': 'form' };
customElements.define('user-edit-offer', class extends Component {
static get observedAttributes() {
return ['mode', 'state' , 'offer-id', 'description', 'picture-url', 'price-range-min', 'price-range-max'];
return ['mode', 'state', 'offer-id', 'description', 'picture-url', 'price-range-min', 'price-range-max'];
}
constructor() {
super(`
<style>
:host {
display: block;
}
#view, #form {
display: none;
}
:host { display: block; }
#view, #form { display: none; }
:host([mode='view']) #view { display: block; }
:host([mode='form']) #form { display: block; }
:host([state='Finished']) #finishForm { display: none; }
#actions {
width: 120px;
}
@ -36,14 +33,14 @@ customElements.define('user-edit-offer', class extends Component {
margin-left: 16px;
}
}
${BUTTON_STYLE}
${ BUTTON_STYLE }
</style>
<section id="view">
<slot></slot>
<div id="actions">
<div id="state"></div>
<input type="button" value="Edytuj" id="edit" />
<form action="/offers/finish" method="post">
<form id="finishForm" action="/offers/finish" method="post">
<input type="hidden" name="id" class="id" value="" />
<input type="submit" slot="action" id="finish" value="Zakończ" />
</form>

View File

@ -17,7 +17,7 @@ input[type="button"], input[type="submit"], button {
transition: color .15s ease-in-out,
background-color .15s ease-in-out,
border-color .15s ease-in-out,
box-shadow .15s ease-in-out,
box-shadow .15s ease-in-out;
width: auto;
height: calc(1.5em + 0.75rem + 2px);
padding: .375rem .75rem;

View File

@ -1,8 +1,63 @@
{% extends "../base.html" %}
{% block content %}
{% if account.is_some() %}
<section>
<a href="/account/offers" class="btn">Opublikuj</a>
</section>
{% endif %}
<marketplace-offers>
<h2 style="text-align: center">Rzeczy wystawione na sprzedaż</h2>
{% for offer in my_offers %}
<user-edit-offer
state="{{offer.state.as_str()}}"
offer-id="{{offer.id}}"
description="{{offer.description}}"
picture-url="{{offer.picture_url}}"
{% match offer.price_range %}
{% when PriceRange::Free %}
price-range-min="0"
price-range-max="0"
{% when PriceRange::Fixed with { value } %}
price-range-min="{{value}}"
price-range-max="0"
{% when PriceRange::Range with { min, max } %}
price-range-min="{{min}}"
price-range-max="{{max}}"
{% endmatch %}
>
<marketplace-offer
offer-id="{{offer.id}}"
description="{{offer.description}}"
picture-url="{{offer.picture_url}}"
{% match offer.price_range %}
{% when PriceRange::Free %}
price-range-min="0"
price-range-max="0"
{% when PriceRange::Fixed with { value } %}
price-range-min="{{value}}"
price-range-max="0"
{% when PriceRange::Range with { min, max } %}
price-range-min="{{min}}"
price-range-max="{{max}}"
{% endmatch %}
>
<contact-info-list slot="contacts">
{% for contact in offer.contacts %}
<contact-info
mode="icon"
contact-id="{{contact.id}}"
contact-type="{{contact.contact_type}}"
content="{{h.render_contact(contact.contact_type.as_str(), contact.content.as_str())}}"
></contact-info>
{% endfor %}
</contact-info-list>
</marketplace-offer>
</user-edit-offer>
{% endfor %}
{% for offer in offers %}
<marketplace-offer
offer-id="{{offer.id}}"

View File

@ -8,14 +8,15 @@
<span>OS Wilno</span>
</ow-path>
{% if page.is_public() -%}
<ow-path path="/" selected="{{ page.select_index() }}" title="Lokalne usługi">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 511.999 511.999" xml:space="preserve">
<path d="M440.482 50.916c-8.099-4.226-18.091-1.088-22.321 7.013l-41.925 80.336-46.147 36.662h-54.683l-57.033-18.756-33.145-53.595 5.854-5.694c3.554-3.457 3.634-9.143.176-12.697l-13.735-14.12 10.294-10.014c4.024-3.914 4.113-10.35.198-14.374l-41.438-42.6c-3.914-4.024-10.35-4.113-14.374-.198l-66.5 64.687c-4.024 3.914-4.113 10.35-.198 14.374l41.438 42.599c3.914 4.024 10.35 4.113 14.374.198l10.294-10.013 13.737 14.121c3.449 3.547 9.136 3.64 12.696.176l2.896-2.817 32.466 52.499a16.544 16.544 0 0 0 8.901 7.014l58.436 19.218.008 287.213c0 10.964 8.888 19.853 19.852 19.853s19.852-8.888 19.852-19.853V333.466l8.565-2.239 24.462 64.136-17.398 78.459c-2.373 10.704 4.38 21.306 15.084 23.679 10.69 2.373 21.303-4.371 23.679-15.083l18.771-84.647a19.858 19.858 0 0 0-1.096-12.026l-24.153-57.154V202.66l51.197-40.674a16.547 16.547 0 0 0 4.375-5.299l43.551-83.45c4.23-8.1 1.089-18.094-7.01-22.321zM171.921 90.467a16.48 16.48 0 0 0-12.357 2.058c-6.031 3.73-8.81 10.704-7.514 17.272l-.092.088-7.475-7.683 20.167-19.617 7.475 7.684-.204.198z"/>
<circle cx="304.734" cy="129.707" r="34.286"/>
{# <ow-path path="/zero-waste" selected="{{ page.select_marketplace() }}" title="Za darmo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" xml:space="preserve">
<path d="M21.787 265.97c0-93.686 60.433-175.027 147.281-203.282l-24.251 32.157c-3.623 4.804-2.666 11.634 2.137 15.256a10.84 10.84 0 0 0 6.551 2.197c3.302 0 6.565-1.496 8.706-4.335l42.916-56.904a10.893 10.893 0 0 0-5.155-16.861l-67.399-23.176c-5.69-1.954-11.888 1.07-13.844 6.759-1.955 5.69 1.07 11.888 6.759 13.844l33.485 11.515c-39.951 13.768-75.875 38.241-103.475 70.935C19.71 156.465 0 210.409 0 265.97c0 27.261 4.631 54.007 13.765 79.493 1.595 4.45 5.786 7.221 10.255 7.221 1.22 0 2.461-.207 3.674-.642 5.664-2.029 8.609-8.266 6.58-13.93-8.285-23.121-12.487-47.393-12.487-72.142zM414.025 402.991c-4.588-3.893-11.461-3.332-15.356 1.255-40.749 48.005-100.185 75.538-163.068 75.538-53.27 0-104.061-19.763-143.119-54.987l40.061 4.936c5.965.74 11.408-3.508 12.143-9.48.735-5.971-3.509-11.408-9.48-12.143l-70.739-8.715a10.896 10.896 0 0 0-12.025 12.895l13.628 69.958c1.013 5.202 5.572 8.813 10.681 8.813.691 0 1.391-.066 2.095-.204 5.905-1.15 9.76-6.871 8.609-12.776l-6.743-34.615c42.647 37.25 97.454 58.105 154.886 58.105 69.292 0 134.783-30.334 179.679-83.226 3.898-4.587 3.334-11.462-1.252-15.354zM509.325 288.789c-3.949-4.538-10.829-5.017-15.369-1.069l-27.12 23.593a236.333 236.333 0 0 0 4.366-45.343c0-55.56-19.71-109.503-55.497-151.896-35.361-41.885-84.382-70.28-138.033-79.955-5.917-1.072-11.586 2.866-12.653 8.788-1.068 5.921 2.866 11.586 8.787 12.654C375.561 73.91 449.415 162.4 449.415 265.969c0 14.664-1.487 29.157-4.413 43.346l-15.46-36.465c-2.349-5.539-8.745-8.124-14.281-5.777-5.539 2.349-8.126 8.742-5.778 14.281l27.821 65.619a10.89 10.89 0 0 0 17.179 3.966l53.772-46.781c4.54-3.95 5.018-10.83 1.07-15.369z"/>
<path d="M188.028 130.89a50.918 50.918 0 0 0-4.574-.207c-21.752 0-40.793 14.02-47.564 34.164-17.981 7.019-30.042 24.311-30.042 44.123a47.444 47.444 0 0 0 11.151 30.53 67.61 67.61 0 0 0-1.206 12.72c0 36.454 29.03 66.112 64.714 66.112 6.157 0 12.253-.886 18.119-2.63.11-.033.222-.059.333-.092a529.09 529.09 0 0 1-.877 107.238 10.891 10.891 0 0 0 10.829 12.088h53.379a10.896 10.896 0 0 0 10.828-12.088 529.532 529.532 0 0 1-1.495-100.106c17.407-.964 33.696-8.121 46.232-20.417 11.715-11.489 19.022-26.339 21-42.412 15.913-7.877 26.498-24.415 26.498-42.538 0-23.342-16.958-42.798-39.2-46.695-7.81-27.348-31.586-46.41-59.334-46.41a57.88 57.88 0 0 0-4.029.141c-9.275-8.797-21.549-13.741-34.507-13.741-16.076.004-30.876 7.585-40.255 20.22zm32.91 282.263a550.944 550.944 0 0 0-.314-99.862 68.285 68.285 0 0 1 20.675 4.615 71.561 71.561 0 0 0 8.631 2.762 551.612 551.612 0 0 0 .333 92.485h-29.325zm-17.889-265.307c4.906-9.489 14.577-15.385 25.237-15.385 8.511 0 16.501 3.771 21.924 10.348a10.89 10.89 0 0 0 10.256 3.805 37.464 37.464 0 0 1 6.354-.551c19.726 0 36.41 15.343 39.668 36.483.83 5.388 5.53 9.307 10.966 9.232l.493-.016c14.127 0 25.62 11.493 25.62 25.62 0 11.212-7.49 21.298-18.217 24.529a10.896 10.896 0 0 0-7.749 10.2c-.573 27.004-23.015 48.973-50.026 48.973-6.323 0-12.48-1.161-18.3-3.45-10.586-4.165-21.761-6.264-32.818-6.264-8.172 0-16.283 1.147-24.042 3.455a41.728 41.728 0 0 1-11.907 1.726c-23.671 0-42.927-19.884-42.927-44.325 0-4.38.624-8.722 1.855-12.905a10.895 10.895 0 0 0-3.206-11.212 25.651 25.651 0 0 1-8.595-19.135c0-11.949 8.114-22.2 19.73-24.93a10.893 10.893 0 0 0 8.207-8.556c2.555-13.336 14.279-23.015 27.881-23.015 2.429 0 4.843.307 7.174.914a10.9 10.9 0 0 0 12.422-5.541z"/>
<path d="M264.285 208.492c9.069 6.257 14.271 15.333 14.271 24.897 0 6.017 4.878 10.894 10.894 10.894 6.015 0 10.894-4.877 10.894-10.894 0-16.834-8.632-32.445-23.683-42.83-4.953-3.416-11.736-2.171-15.153 2.78-3.419 4.951-2.174 11.736 2.777 15.153zM234.981 191.995l.338.001h.085c5.977 0 10.846-4.823 10.891-10.811.046-6.017-4.794-10.931-10.81-10.976l-.503-.002c-6.017 0-10.894 4.877-10.894 10.894.001 6.016 4.877 10.894 10.893 10.894z"/>
</svg>
<div>Lokalne Usługi</div>
</ow-path>
</ow-path> #}
{% if page.is_public() -%}
<ow-path path="/marketplace" selected="{{ page.select_marketplace() }}" title="Targ">
<svg viewBox="0 0 484.909 484.909" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path d="M204.993 438.478c-6.347 6.349-6.347 16.639 0 22.978a16.196 16.196 0 0 0 11.488 4.761c4.158 0 8.316-1.587 11.489-4.761l49.747-49.754-22.979-22.978zm112.649-112.671-16.947 16.954 22.976 22.977 39.926-39.931zm-56.872 0h-45.954l135.627 135.648a16.193 16.193 0 0 0 11.487 4.761c4.158 0 8.315-1.587 11.488-4.761 6.349-6.339 6.349-16.629 0-22.978zM102.294 107.658c21.471 0 38.878-19.915 38.878-44.478 0-24.564-17.407-44.487-38.878-44.487-21.486 0-38.877 19.923-38.877 44.487 0 24.563 17.391 44.478 38.877 44.478zm-15.17 48.128c-58.083-103.857-29.041-51.929 0 0z"/>
@ -25,6 +26,13 @@
</svg>
<div>Targ</div>
</ow-path>
<ow-path path="/" selected="{{ page.select_index() }}" title="Lokalne usługi">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 511.999 511.999" xml:space="preserve">
<path d="M440.482 50.916c-8.099-4.226-18.091-1.088-22.321 7.013l-41.925 80.336-46.147 36.662h-54.683l-57.033-18.756-33.145-53.595 5.854-5.694c3.554-3.457 3.634-9.143.176-12.697l-13.735-14.12 10.294-10.014c4.024-3.914 4.113-10.35.198-14.374l-41.438-42.6c-3.914-4.024-10.35-4.113-14.374-.198l-66.5 64.687c-4.024 3.914-4.113 10.35-.198 14.374l41.438 42.599c3.914 4.024 10.35 4.113 14.374.198l10.294-10.013 13.737 14.121c3.449 3.547 9.136 3.64 12.696.176l2.896-2.817 32.466 52.499a16.544 16.544 0 0 0 8.901 7.014l58.436 19.218.008 287.213c0 10.964 8.888 19.853 19.852 19.853s19.852-8.888 19.852-19.853V333.466l8.565-2.239 24.462 64.136-17.398 78.459c-2.373 10.704 4.38 21.306 15.084 23.679 10.69 2.373 21.303-4.371 23.679-15.083l18.771-84.647a19.858 19.858 0 0 0-1.096-12.026l-24.153-57.154V202.66l51.197-40.674a16.547 16.547 0 0 0 4.375-5.299l43.551-83.45c4.23-8.1 1.089-18.094-7.01-22.321zM171.921 90.467a16.48 16.48 0 0 0-12.357 2.058c-6.031 3.73-8.81 10.704-7.514 17.272l-.092.088-7.475-7.683 20.167-19.617 7.475 7.684-.204.198z"/>
<circle cx="304.734" cy="129.707" r="34.286"/>
</svg>
<div>Lokalne Usługi</div>
</ow-path>
<ow-path path="/news" selected="{{ page.select_news() }}" title="Aktualności">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 508 508" xml:space="preserve">
<path d="M437.4 197.6H307.6c-7.8 0-14.2 6.3-14.2 14.1v141.1c0 7.8 6.3 14.1 14.1 14.1h129.9c7.8 0 14.1-6.3 14.1-14.1V211.7c0-7.8-6.3-14.1-14.1-14.1zm-14 141.1H321.7V225.8h101.7v112.9zM360.7 409.3H70.6c-7.8 0-14.1 6.3-14.1 14.1-.1 7.7 6.3 14.1 14.1 14.1h290.1c7.8 0 14.1-6.3 14.1-14.1s-6.3-14.1-14.1-14.1zM251.2 338.7H70.6c-7.8 0-14.1 6.3-14.1 14.1-.1 7.8 6.3 14.1 14.1 14.1h180.6c7.8 0 14.1-6.3 14.1-14.1s-6.3-14.1-14.1-14.1zM251.2 268.1H70.6c-7.8 0-14.1 6.3-14.1 14.1-.1 7.8 6.3 14.1 14.1 14.1h180.6c7.8 0 14.1-6.3 14.1-14.1s-6.3-14.1-14.1-14.1zM251.2 197.6H70.6c-7.8 0-14.1 6.3-14.1 14.1-.1 7.8 6.3 14.1 14.1 14.1h180.6c7.8 0 14.1-6.3 14.1-14.1s-6.3-14.1-14.1-14.1z"/>
@ -50,19 +58,6 @@
</ow-path>
{%- endif %}
{% if account.is_some() -%}
<ow-path path="/account/offers" selected="{{ page.select_account_offers() }}" title="Moje sprzedaże">
<svg viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path
d="M30.412 19.045a.34.34 0 0 0-.34.341V30.83c0 .12-.102.222-.222.222h-2.627v-3.14h.87a.402.402 0 0 0 .372-.22.402.402 0 0 0-.054-.43l-1.818-2.346a.436.436 0 0 0-.346-.173h-.003a.437.437 0 0 0-.347.179l-1.758 2.343a.403.403 0 0 0-.049.429.403.403 0 0 0 .372.218h.806v3.14h-8.941a.594.594 0 0 1-.594-.594V19.716c0-.327.266-.594.594-.594H27.7a.34.34 0 1 0 0-.681H16.327c-.703 0-1.275.572-1.275 1.275v10.742c0 .703.572 1.275 1.275 1.275h9.282a.34.34 0 0 0 .34-.34V27.57a.34.34 0 0 0-.34-.34h-.592l1.233-1.645 1.274 1.645h-.642a.34.34 0 0 0-.34.34v3.821a.34.34 0 0 0 .34.34h2.968a.905.905 0 0 0 .903-.903V19.386a.34.34 0 0 0-.34-.34z"
/>
<path
d="M17.52 15.715c-.638-.713-5.53-6.169-7.115-7.557 1.257-.794 2.022-2.14 2.022-3.61C12.427 2.168 10.42.23 7.952.23c-2.468 0-4.475 1.938-4.475 4.32 0 1.455.75 2.789 1.986 3.586-1.026.75-1.648 1.93-1.648 3.186v18.466c0 .971.819 1.761 1.825 1.761s1.824-.79 1.824-1.76V19.643h.938v10.143c0 .971.819 1.761 1.825 1.761s1.824-.79 1.824-1.76l.036-15.054 3.216 3.104c.304.294.704.44 1.104.44.4 0 .8-.146 1.104-.44a1.472 1.472 0 0 0 .008-2.123z"
/>
</svg>
</ow-path>
{%- endif %}
{% if h.is_admin(account) -%}
<ow-path path="/admin" selected="{{ page.select_admin_news() }}" title="Admin">
<svg viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg">

View File

@ -4,41 +4,5 @@
<h2>Sprzedaż niepotrzebnych rzeczy</h2>
<offer-form></offer-form>
{% for offer in offers %}
<user-edit-offer
state="{{offer.state.as_str()}}"
offer-id="{{offer.id}}"
description="{{offer.description}}"
picture-url="{{offer.picture_url}}"
{% match offer.price_range %}
{% when PriceRange::Free %}
price-range-min="0"
price-range-max="0"
{% when PriceRange::Fixed with { value } %}
price-range-min="{{value}}"
price-range-max="0"
{% when PriceRange::Range with { min, max } %}
price-range-min="{{min}}"
price-range-max="{{max}}"
{% endmatch %}
>
<marketplace-offer
offer-id="{{offer.id}}"
description="{{offer.description}}"
picture-url="{{offer.picture_url}}"
{% match offer.price_range %}
{% when PriceRange::Free %}
price-range-min="0"
price-range-max="0"
{% when PriceRange::Fixed with { value } %}
price-range-min="{{value}}"
price-range-max="0"
{% when PriceRange::Range with { min, max } %}
price-range-min="{{min}}"
price-range-max="{{max}}"
{% endmatch %}
></marketplace-offer>
</user-edit-offer>
{% endfor %}
</marketplace-offers>
{% endblock %}

View File

@ -67,7 +67,7 @@ impl Page {
}
pub fn select_marketplace(&self) -> &str {
if matches!(self, Page::Marketplace) {
if matches!(self, Page::Marketplace | Page::AccountOffers) {
"selected"
} else {
""
@ -97,14 +97,6 @@ impl Page {
""
}
}
pub fn select_account_offers(&self) -> &str {
if matches!(self, Page::AccountOffers) {
"selected"
} else {
""
}
}
}
#[derive(Debug, Default, PartialEq, Eq, Serialize, Deserialize)]

View File

@ -30,7 +30,7 @@ ORDER BY id DESC
}
#[tracing::instrument]
pub async fn visible_offers(t: &mut T<'_>) -> Result<Vec<db::Offer>> {
pub async fn visible_offers(t: &mut T<'_>, account_id: Option<i32>) -> Result<Vec<db::Offer>> {
sqlx::query_as(
r#"
SELECT
@ -42,10 +42,11 @@ SELECT
state,
created_at
FROM offers
WHERE created_at + '2 weeks' > now() AND state = 'Approved'
WHERE (created_at + '2 weeks' > now() AND state = 'Approved') OR owner_id = $1
ORDER BY id DESC
"#,
)
.bind(account_id)
.fetch_all(t)
.await
.map_err(|e| {

View File

@ -1,15 +1,12 @@
use std::sync::Arc;
use actix_web::web::{Data, Form, ServiceConfig};
use actix_web::{get, post, web, HttpResponse};
use askama::*;
use serde::Deserialize;
use sqlx::PgPool;
use crate::model::db::{self, OfferState, PriceRange};
use crate::model::db::{self, OfferState};
use crate::model::view;
use crate::model::view::Page;
use crate::queries::T;
use crate::routes::{Identity, Result};
use crate::view::Helper;
use crate::{authorize, not_xss, ok_or_internal, queries};
@ -21,24 +18,6 @@ struct AccountOffersTemplate {
error: Option<String>,
page: Page,
h: Helper,
offers: Vec<view::Offer>,
}
async fn offers(t: &mut T<'_>, account_id: i32) -> Vec<view::Offer> {
let offers = queries::account_offers(t, account_id)
.await
.unwrap_or_default();
let contacts = queries::all_contacts(t)
.await
.unwrap_or_default()
.into_iter()
.map(Arc::new)
.collect::<Vec<_>>();
offers
.into_iter()
.map(|o| view::Offer::from((o, &contacts)))
.collect::<Vec<_>>()
}
#[get("/account/offers")]
@ -47,14 +26,11 @@ pub async fn account_offers(id: Identity, db: Data<PgPool>) -> Result<HttpRespon
let mut t = ok_or_internal!(pool.begin().await);
let account = authorize!(&mut t, id);
let offers = offers(&mut t, account.id).await;
t.commit().await.ok();
Ok(HttpResponse::Ok().content_type("text/html").body(
AccountOffersTemplate {
account: Some(account),
offers,
page: Page::AccountOffers,
..Default::default()
}
@ -93,19 +69,17 @@ async fn create_offer(
Ok(_) => {
t.commit().await.ok();
Ok(HttpResponse::SeeOther()
.append_header(("Location", "/account/offers"))
.append_header(("Location", "/marketplace"))
.finish())
}
Err(e) => {
dbg!(e);
let offers = offers(&mut t, account.id).await;
t.rollback().await.ok();
Ok(HttpResponse::Ok().content_type("text/html").body(
AccountOffersTemplate {
account: Some(account),
offers,
page: Page::AccountOffers,
error: Some("Problem z utworzeniem wpisu".into()),
..Default::default()
@ -147,19 +121,16 @@ async fn update_offer(
Ok(_) => {
t.commit().await.ok();
Ok(HttpResponse::SeeOther()
.append_header(("Location", "/account/offers"))
.append_header(("Location", "/marketplace"))
.finish())
}
Err(e) => {
dbg!(e);
let offers = offers(&mut t, account.id).await;
t.rollback().await.ok();
Ok(HttpResponse::Ok().content_type("text/html").body(
AccountOffersTemplate {
account: Some(account),
offers,
page: Page::AccountOffers,
error: Some("Problem z utworzeniem wpisu".into()),
..Default::default()
@ -192,17 +163,15 @@ async fn user_finish_offer(
Ok(_) => {
t.commit().await.ok();
Ok(HttpResponse::SeeOther()
.append_header(("Location", "/account/offers"))
.append_header(("Location", "/marketplace"))
.finish())
}
Err(e) => {
dbg!(e);
let offers = offers(&mut t, account.id).await;
t.rollback().await.ok();
Ok(HttpResponse::Ok().content_type("text/html").body(
AccountOffersTemplate {
account: Some(account),
offers,
page: Page::AccountOffers,
error: Some("Problem z utworzeniem wpisu".into()),
..Default::default()

View File

@ -22,6 +22,7 @@ struct MarketplaceTemplate {
#[serde(skip)]
h: Helper,
offers: Vec<view::Offer>,
my_offers: Vec<view::Offer>,
}
#[get("")]
@ -40,32 +41,37 @@ async fn marketplace(req: HttpRequest, db: Data<PgPool>, id: Identity) -> Result
.map(Arc::new)
.collect::<Vec<_>>();
let offers = queries::visible_offers(&mut t)
let mut offers = queries::visible_offers(&mut t, account.as_ref().map(|a| a.id))
.await
.unwrap_or_default()
.into_iter()
.map(|o| view::Offer::from((o, &contacts)))
.collect::<Vec<_>>();
let my_offers = account
.as_ref()
.map(|a| {
offers
.drain_filter(|o| o.owner_id == a.id)
.collect::<Vec<_>>()
})
.unwrap_or_default();
t.commit().await.ok();
let template = MarketplaceTemplate {
page: Page::Marketplace,
account,
offers,
my_offers,
..Default::default()
};
match req.headers().get("accept").and_then(|h| h.to_str().ok()) {
Some("application/json") => Ok(HttpResponse::Ok().json(MarketplaceTemplate {
page: Page::Marketplace,
account,
offers,
..Default::default()
})),
_ => Ok(HttpResponse::Ok().content_type("text/html").body(
MarketplaceTemplate {
page: Page::Marketplace,
account,
offers,
..Default::default()
}
.render()
.unwrap(),
)),
Some("application/json") => Ok(HttpResponse::Ok().json(template)),
_ => Ok(HttpResponse::Ok()
.content_type("text/html")
.body(template.render().unwrap())),
}
}