From 8ed90a114ce8cab8bcbd51915b1efc711a392d0f Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 18 Feb 2020 10:23:15 -0700 Subject: [PATCH 01/18] fix: use new tag buttons in current filters, use Pinecone search form --- resources/views/404.blade.php | 2 +- resources/views/index.blade.php | 2 +- resources/views/partials/current-filters.blade.php | 6 +++--- resources/views/search.blade.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/404.blade.php b/resources/views/404.blade.php index ec45fd0..95212ac 100644 --- a/resources/views/404.blade.php +++ b/resources/views/404.blade.php @@ -7,6 +7,6 @@
{{ __('Sorry, but the page you were trying to view does not exist.', 'coop-library') }}
- {!! get_search_form(false) !!} + @include('partials.search-form', ['placeholder' => __('Search resource name, publisher, or topic…')]) @endif @endsection diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index ffe1155..df391ec 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -7,7 +7,7 @@
{{ __('Sorry, no results were found.', 'coop-library') }}
- {!! get_search_form(false) !!} + @include('partials.search-form', ['placeholder' => __('Search resource name, publisher, or topic…')]) @endif @include('partials.filters') diff --git a/resources/views/partials/current-filters.blade.php b/resources/views/partials/current-filters.blade.php index 3ef73b0..8f0c1f7 100644 --- a/resources/views/partials/current-filters.blade.php +++ b/resources/views/partials/current-filters.blade.php @@ -1,12 +1,12 @@ @if(!empty(array_filter($queried_resource_terms)))

Showing {{ $found_posts }} of {{ App::totalPosts('lc_resource') }} resources

-
+ @endif + @endif diff --git a/resources/views/partials/save-search.blade.php b/resources/views/partials/save-search.blade.php new file mode 100644 index 0000000..b78c37f --- /dev/null +++ b/resources/views/partials/save-search.blade.php @@ -0,0 +1,5 @@ +
+
+ +
+
diff --git a/resources/views/search.blade.php b/resources/views/search.blade.php index 6255df8..693f0a0 100644 --- a/resources/views/search.blade.php +++ b/resources/views/search.blade.php @@ -12,6 +12,7 @@ @include('partials.filters') @include('partials.sort') + @include('partials.save-search') @include('partials.current-filters')
+ `; + } + const savedSearch = document.createElement('div'); + savedSearch.className = 'saved-search'; + savedSearch.innerHTML = ` +

${item.name}

+ +
+

+ ${__('Search term', 'coop-library')}
+ “${item.term}” +

+ ${tagsList} +
+
+ `; + + savedSearchContainer.appendChild(savedSearch); + + const disclosureLabels = document.querySelectorAll( '.disclosure-label' ); + + if ( disclosureLabels ) { + Array.prototype.forEach.call( disclosureLabels, label => { + new Pinecone.DisclosureButton( label ); + } ); + } + }); + } + const removeAllButton = document.getElementById('remove-all'); + if(removeAllButton) { + new Pinecone.Dialog( removeAllButton, { + title: __('Remove saved searches?', 'coop-library'), + question: __('Are you sure you want to remove all of your saved searches?', 'coop-library'), + confirm: __('Yes, remove', 'coop-library'), + dismiss: __('No, don’t remove', 'coop-library'), + callback: function callback() { + try { + localStorage.setItem('saved-searches', ''); + savedSearchContainer.innerHTML = ''; + removeAllButton.parentNode.removeChild(removeAllButton); + addNotification(__('Saved searches removed', 'coop-library'), __('Your saved searches have been removed.', 'coop-library'), 'success'); + } catch(error) { + addNotification(__('Saved searches not removed', 'coop-library'), __('Your saved searches could not be removed.', 'coop-library'), 'error'); + } + }, + }); + } + document.addEventListener('click', (event) => { + if (!event.target.classList.contains('remove-saved-search')) return; + try { + const length = document.querySelectorAll('.saved-search').length; + const key = event.target.dataset.key; + let savedSearches = localStorage.getItem('saved-searches'); + savedSearches = savedSearches ? JSON.parse(savedSearches) : {}; + delete savedSearches[key]; + localStorage.setItem('saved-searches', JSON.stringify(savedSearches)); + event.target.parentNode.parentNode.parentNode.removeChild(event.target.parentNode.parentNode); + if (length === 1) { + removeAllButton.parentNode.removeChild(removeAllButton); + } + addNotification(__('Saved search removed', 'coop-library'), __('Your saved search has been removed.', 'coop-library'), 'success'); + } catch(error) { + addNotification(__('Saved search not removed', 'coop-library'), __('Your saved search could not be removed.', 'coop-library'), 'error'); + } + }); + }, + finalize() { + // JavaScript to be fired on the Saved Searches page, after the init JS + }, +}; diff --git a/resources/assets/styles/layouts/_pages.scss b/resources/assets/styles/layouts/_pages.scss index 1baf81d..34501ce 100644 --- a/resources/assets/styles/layouts/_pages.scss +++ b/resources/assets/styles/layouts/_pages.scss @@ -17,111 +17,26 @@ } } -// TODO: Remove after Pinecone 1.0.0-alpha.11 is merged. - -main { - position: relative; -} - -.notification { - margin-bottom: $gutter; - position: sticky; - top: $gutter; - z-index: 1; +#saved-searches:not(:empty) + .notification { + display: none; } -.button--borderless.button--destructive { - --color: var(--red-500); - --outline-color: var(--red-500); - --hover-color: var(--dark-mint-500); - --focus-color: var(--red-500); - --active-color: var(--white); - --active-background-color: var(--red-500); -} - -.align-right { - text-align: right; -} - -.align-right .button--borderless { - display: inline-block; - margin: rem(6) rem(-8) rem(6) rem(24); -} - -.page.page-template-page-favorites .cards .card__wrapper { - display: grid; - grid-template-columns: 100%; - grid-template-rows: 1fr 3rem; - gap: rem(20); -} - -@include breakpoint-up(sm) { - .page.page-template-page-favorites { - .cards { - display: flex; - flex-direction: row; - flex-wrap: wrap; - - @supports (display: $grid) { - display: grid; - gap: rem(30); - grid-template-columns: 100%; - } - } - - .cards .card__wrapper { - margin-bottom: rem(30); - width: 100%; - - @supports (display: $grid) { - margin-bottom: 0; - } - } - - .card:nth-child(even) { - margin-left: 0; - } - } +#saved-searches { + margin-top: rem(20); } -@include breakpoint-up(md) { - .page.page-template-page-favorites { - .cards { - @supports (display: $grid) { - grid-template-columns: repeat(2, 1fr); - } - } - - .cards .card__wrapper { - width: calc(50% - #{rem(30)} / 2); - - @supports (display: $grid) { - width: 100%; - } - } - - .card:nth-child(even) { - margin-left: rem(30); - - @supports (display: $grid) { - margin-left: 0; - } - } - - .cards .card__wrapper + .card__wrapper { - margin-top: 0; - } - } -} +.saved-search { + position: relative; + border-top: solid 1px var(--dark-mint-500); + padding-top: rem(24); -@include breakpoint-up(lg) { - .page.page-template-page-favorites main { - @include grid-column-span(8, 12, 3); + [aria-expanded="false"] { + margin-bottom: 0; } -} -@include breakpoint-up(xl) { - .page.page-template-page-favorites main { - @include grid-column-span(8, 16, 4); + .align-right { + position: absolute; + bottom: rem(20); + right: 0; } } diff --git a/resources/views/page-saved-searches.blade.php b/resources/views/page-saved-searches.blade.php new file mode 100644 index 0000000..e4cfa13 --- /dev/null +++ b/resources/views/page-saved-searches.blade.php @@ -0,0 +1,11 @@ +{{-- + Template Name: Saved Searches +--}} +@extends('layouts.app') + +@section('content') + @while(have_posts()) @php the_post() @endphp + @include('partials.page-header') + @include('partials.content-page-saved-searches') + @endwhile +@endsection diff --git a/resources/views/partials/content-page-saved-searches.blade.php b/resources/views/partials/content-page-saved-searches.blade.php new file mode 100644 index 0000000..e582be6 --- /dev/null +++ b/resources/views/partials/content-page-saved-searches.blade.php @@ -0,0 +1,6 @@ + +
+
+

@svg('info', 'icon icon--info', ['aria-hidden' => true, 'focusable' => false]) {{ __('No saved searches', 'coop-library') }}

+
{!! __('Looks like you haven’t saved any searches yet.', 'coop-library') !!}
+
diff --git a/resources/views/partials/search-form.blade.php b/resources/views/partials/search-form.blade.php index 727e49a..c70490a 100644 --- a/resources/views/partials/search-form.blade.php +++ b/resources/views/partials/search-form.blade.php @@ -1,7 +1,7 @@
-
-

@svg('info', 'icon icon--info', ['aria-hidden' => true, 'focusable' => false]) {{ __('No saved searches', 'coop-library') }}

-
{!! __('Looks like you haven’t saved any searches yet.', 'coop-library') !!}
+
+

{{__('You have no saved searches.', 'coop-library') }}

+

{!! sprintf(__('Search or browse for resources to save your search.', 'coop-library'), get_post_type_archive_link('lc_resource')) !!}

From fb961dcf1fffdd41ec653633d01853934bc77ed0 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Fri, 21 Feb 2020 16:15:48 -0700 Subject: [PATCH 09/18] feat: limit saved searches to 50 instead of 25 --- resources/assets/scripts/routes/archive.js | 6 +++--- resources/assets/scripts/routes/saved-searches.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/assets/scripts/routes/archive.js b/resources/assets/scripts/routes/archive.js index 76253ab..63f19ad 100644 --- a/resources/assets/scripts/routes/archive.js +++ b/resources/assets/scripts/routes/archive.js @@ -75,11 +75,11 @@ export default { let savedSearches = localStorage.getItem('saved-searches'); savedSearches = savedSearches ? JSON.parse(savedSearches) : {}; - if (Object.entries(savedSearches).length === 25) { + if (Object.entries(savedSearches).length === 50) { saveSearchButton.onclick = () => { addNotification( __('Maximum number of saved searches reached', 'coop-library'), - sprintf(__('You have reached the maximum amount of saved searches (25). To save more, you must delete some saved searches.', 'coop-library'), CoopLibrary.savedSearchesLink), + sprintf(__('You have reached the maximum amount of saved searches (50). To save more, you must delete some saved searches.', 'coop-library'), CoopLibrary.savedSearchesLink), 'error' ); }; @@ -107,7 +107,7 @@ export default { }); savedSearches[now] = {name, term, url, filters}; localStorage.setItem('saved-searches', JSON.stringify(savedSearches)); - const remaining = 25 - Object.keys(savedSearches).length; + const remaining = 50 - Object.keys(savedSearches).length; addNotification( __('Search saved', 'coop-library'), sprintf( diff --git a/resources/assets/scripts/routes/saved-searches.js b/resources/assets/scripts/routes/saved-searches.js index dfa0428..cdb3034 100644 --- a/resources/assets/scripts/routes/saved-searches.js +++ b/resources/assets/scripts/routes/saved-searches.js @@ -10,10 +10,10 @@ export default { savedSearches = savedSearches ? JSON.parse(savedSearches) : {}; savedSearches = Object.entries(savedSearches); - if (savedSearches.length === 25) { + if (savedSearches.length === 50) { addNotification( __('Maximum number of saved searches reached', 'coop-library'), - __('You have reached the maximum amount of saved searches (25). To save more, you must delete some saved searches.', 'coop-library'), + __('You have reached the maximum amount of saved searches (50). To save more, you must delete some saved searches.', 'coop-library'), 'warning' ); } From 9549bf5b4568b9d6cc0a9c4affca0a30439cd971 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Fri, 21 Feb 2020 16:18:10 -0700 Subject: [PATCH 10/18] fix: resolve PHPCS error --- app/admin.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/admin.php b/app/admin.php index f47010d..f119401 100644 --- a/app/admin.php +++ b/app/admin.php @@ -20,5 +20,11 @@ * Customizer JS */ add_action('customize_preview_init', function () { - wp_enqueue_script('coop-library/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); + wp_enqueue_script( + 'coop-library/customizer.js', + asset_path('scripts/customizer.js'), + ['customize-preview'], + null, + true + ); }); From e7a96008886559b5c5e3edf4123e8652d87e689e Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 25 Feb 2020 09:31:22 -0700 Subject: [PATCH 11/18] fix: paginate search results --- app/Controllers/App.php | 13 +++++++++++++ resources/views/search.blade.php | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/app/Controllers/App.php b/app/Controllers/App.php index 5617039..3636fb0 100644 --- a/app/Controllers/App.php +++ b/app/Controllers/App.php @@ -71,6 +71,19 @@ public function foundPosts() return $wp_query->found_posts; } + public function maxPages() + { + global $wp_query; + return $wp_query->max_num_pages; + } + + public function currentPage() + { + global $wp_query; + $current_page = $wp_query->query_vars['paged'] > 1 ? $wp_query->query_vars['paged'] : 1; + return $current_page; + } + public static function totalPosts($post_type = null) { if ($post_type) { diff --git a/resources/views/search.blade.php b/resources/views/search.blade.php index 693f0a0..a2159c6 100644 --- a/resources/views/search.blade.php +++ b/resources/views/search.blade.php @@ -24,6 +24,10 @@ {{-- TODO: Replace this hack with a better implementation. --}} {!! str_replace(['page-numbers current', 'page-numbers'], ['page current', 'link link--pagination'], get_the_posts_pagination([ + 'base' => @add_query_arg('paged','%#%'), + 'format' => '?paged=%#%', + 'current' => $current_page, + 'total' => $max_pages, 'prev_text' => sprintf('‹ %s', __('previous resources', 'coop-library')), 'next_text' => sprintf(' %s ›', __('next resources', 'coop-library')) ])) !!} From 434e0b2053bc41f429411b79e3e5f7a11d2ebdac Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Fri, 28 Feb 2020 08:36:47 -0700 Subject: [PATCH 12/18] fix: set post type in pre_get_posts --- app/filters.php | 3 +++ resources/views/partials/search-form.blade.php | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/filters.php b/app/filters.php index 60a38c8..d6226be 100644 --- a/app/filters.php +++ b/app/filters.php @@ -94,6 +94,9 @@ * Show twenty resources per page. */ add_filter('pre_get_posts', function ($query) { + if ($query->is_search && !is_admin()) { + $query->set('post_type', ['lc_resource']); + } if ((is_post_type_archive('lc_resource') || is_tax()) && $query->is_main_query()) { if (! empty($_GET['order_by'])) { switch ($_GET['order_by']) { diff --git a/resources/views/partials/search-form.blade.php b/resources/views/partials/search-form.blade.php index c70490a..8f714c0 100644 --- a/resources/views/partials/search-form.blade.php +++ b/resources/views/partials/search-form.blade.php @@ -3,7 +3,6 @@ {{ __('Search for:', 'coop-library') }} -
+

{{__('You have no saved searches.', 'coop-library') }}

From 03ca0b063f753efa0c7c050c1f6baa5780690f7a Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 2 Mar 2020 12:24:27 -0700 Subject: [PATCH 15/18] fix: dialog titles --- resources/assets/scripts/routes/saved-searches.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/assets/scripts/routes/saved-searches.js b/resources/assets/scripts/routes/saved-searches.js index cdb3034..964df7d 100644 --- a/resources/assets/scripts/routes/saved-searches.js +++ b/resources/assets/scripts/routes/saved-searches.js @@ -69,7 +69,7 @@ export default { const removeAllButton = document.getElementById('remove-all'); if(removeAllButton) { new Pinecone.Dialog( removeAllButton, { - title: __('Remove saved searches?', 'coop-library'), + title: __('Confirm remove saved searches', 'coop-library'), question: __('Are you sure you want to remove all of your saved searches?', 'coop-library'), confirm: __('Yes, remove', 'coop-library'), dismiss: __('No, don’t remove', 'coop-library'), @@ -88,7 +88,7 @@ export default { const removeButtons = document.querySelectorAll('.remove-saved-search'); Array.prototype.forEach.call(removeButtons, removeButton => { new Pinecone.Dialog( removeButton, { - title: __('Remove saved search?', 'coop-library'), + title: __('Confirm remove saved search', 'coop-library'), question: __('Are you sure you want to remove this saved search?', 'coop-library'), confirm: __('Yes, remove', 'coop-library'), dismiss: __('No, don’t remove', 'coop-library'), From 404bdb7f5cfad5dabad7fda96e20324b01f53163 Mon Sep 17 00:00:00 2001 From: Jonathan Hung Date: Mon, 2 Mar 2020 16:22:32 -0500 Subject: [PATCH 16/18] fix: add space in remove all button label --- resources/views/partials/content-page-saved-searches.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/partials/content-page-saved-searches.blade.php b/resources/views/partials/content-page-saved-searches.blade.php index c879539..76f7394 100644 --- a/resources/views/partials/content-page-saved-searches.blade.php +++ b/resources/views/partials/content-page-saved-searches.blade.php @@ -1,4 +1,4 @@ - +

{{__('You have no saved searches.', 'coop-library') }}

From 5c3ab0d689490e2b9ea51bde0144bd92bd2ea03b Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 2 Mar 2020 15:13:18 -0700 Subject: [PATCH 17/18] fix: try   inside span --- .../views/partials/content-page-saved-searches.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/partials/content-page-saved-searches.blade.php b/resources/views/partials/content-page-saved-searches.blade.php index 76f7394..f4def6c 100644 --- a/resources/views/partials/content-page-saved-searches.blade.php +++ b/resources/views/partials/content-page-saved-searches.blade.php @@ -1,4 +1,8 @@ - +

{{__('You have no saved searches.', 'coop-library') }}

From e4417705263f0dec6fa090de3c600df57f256a40 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 2 Mar 2020 15:22:57 -0700 Subject: [PATCH 18/18] fix: move   outside span --- resources/views/partials/content-page-saved-searches.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/partials/content-page-saved-searches.blade.php b/resources/views/partials/content-page-saved-searches.blade.php index f4def6c..726aead 100644 --- a/resources/views/partials/content-page-saved-searches.blade.php +++ b/resources/views/partials/content-page-saved-searches.blade.php @@ -1,6 +1,6 @@