Add gitignore and advanced filtering
This commit is contained in:
23
src/main.js
23
src/main.js
@@ -1,16 +1,25 @@
|
||||
import './generated.css'
|
||||
|
||||
import Alpine from 'alpinejs'
|
||||
import persist from '@alpinejs/persist'
|
||||
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.plugin(persist)
|
||||
|
||||
Alpine.data('bookmeterList', () => ({
|
||||
items: [],
|
||||
filteredItems: [],
|
||||
username: '',
|
||||
publisher: '',
|
||||
title: '',
|
||||
author: '',
|
||||
nameFilter: '',
|
||||
async init() {
|
||||
this.$watch('nameFilter', () => this.updateFilter());
|
||||
this.$watch('username', () => this.updateFilter());
|
||||
this.$watch('title', () => this.updateFilter());
|
||||
this.$watch('author', () => this.updateFilter());
|
||||
this.$watch('publisher', () => this.updateFilter());
|
||||
|
||||
let qp = new URLSearchParams(window.location.search);
|
||||
if(qp.get('filter')) this.nameFilter = qp.get('filter');
|
||||
@@ -19,7 +28,7 @@ Alpine.data('bookmeterList', () => ({
|
||||
this.items = await res.json();
|
||||
this.updateFilter();
|
||||
},
|
||||
test(){
|
||||
stats(){
|
||||
return {
|
||||
'pages_total': this.filteredItems.reduce((a, b) => a + b.book.pages, 0) || '-',
|
||||
'likes_total': this.filteredItems.reduce((a, b) => a + b.likes, 0) || '-',
|
||||
@@ -37,8 +46,16 @@ Alpine.data('bookmeterList', () => ({
|
||||
let filter = this.nameFilter.toLowerCase();
|
||||
|
||||
this.filteredItems = this.items.filter(i => {
|
||||
|
||||
return (
|
||||
(!this.username || i.username.toLowerCase().includes(this.username.toLowerCase())) &&
|
||||
(!this.title || i.book.title.toLowerCase().includes(this.title.toLowerCase())) &&
|
||||
(!this.author || i.book.author.toLowerCase().includes(this.author.toLowerCase())) &&
|
||||
(!this.publisher || i.book.publisher.toLowerCase().includes(this.publisher.toLowerCase()))
|
||||
);
|
||||
if(filter.startsWith('@') && i.username.toLowerCase().includes(filter.substring(1))) return true;
|
||||
if (i.book.title.toLowerCase().includes(this.nameFilter.toLowerCase()) || i.book.author.toLowerCase().includes(this.nameFilter.toLowerCase())) return true;
|
||||
if (i.username.toLowerCase().includes(filter) ||
|
||||
i.book.title.toLowerCase().includes(filter) || i.book.author.toLowerCase().includes(filter) || i.book.publisher.toLowerCase().includes(filter)) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user