Some search fixes, switch from created() to fetch() for SSR

This commit is contained in:
Jai A
2020-10-04 20:19:48 -07:00
parent a545d7d8b1
commit 3656e6ef54
5 changed files with 62 additions and 39 deletions

View File

@@ -45,7 +45,7 @@
--color-grey-6: #f7f2eb; --color-grey-6: #f7f2eb;
--color-grey-5: #ede9e4; --color-grey-5: #ede9e4;
--color-grey-4: #dadcd5; --color-grey-4: #dadcd5;
--color-grey-3: #b8bbb4; --color-grey-3: #797b76;
--color-grey-2: #3b3937; --color-grey-2: #3b3937;
--color-grey-1: #3a3b38; --color-grey-1: #3a3b38;
--color-grey-0: #1d1e1b; --color-grey-0: #1d1e1b;

View File

@@ -29,6 +29,7 @@
<svg <svg
:class="{ :class="{
'disabled-paginate': currentPage === pages[pages.length - 1], 'disabled-paginate': currentPage === pages[pages.length - 1],
'active-paginate': currentPage !== pages[pages.length - 1],
}" }"
viewBox="0 0 24 24" viewBox="0 0 24 24"
fill="none" fill="none"
@@ -85,7 +86,8 @@ export default {
color: var(--color-grey-5); color: var(--color-grey-5);
} }
.active-page-number { .active-page-number,
.active-paginate {
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }

View File

@@ -143,18 +143,18 @@
@click="showPopup = !showPopup" @click="showPopup = !showPopup"
/> />
<span> {{ this.$auth.user.username }} </span> <span> {{ this.$auth.user.username }} </span>
</div> <div v-if="showPopup" class="user-actions-popup">
<div v-if="showPopup" class="user-actions-popup"> <div class="popup-inner">
<div class="popup-inner"> <p>
<p> Modrinth ID: <strong>{{ this.$auth.user.id }}</strong>
Modrinth ID: <strong>{{ this.$auth.user.id }}</strong> </p>
</p> <hr />
<hr /> <p>My profile</p>
<p>My profile</p> <p>My teams</p>
<p>My teams</p> <hr />
<hr /> <p>Settings</p>
<p>Settings</p> <p @click="logout">Logout</p>
<p @click="logout">Logout</p> </div>
</div> </div>
</div> </div>
<div v-if="this.$auth.loggedIn" class="notifications"> <div v-if="this.$auth.loggedIn" class="notifications">
@@ -231,15 +231,16 @@
<script> <script>
export default { export default {
async fetch() {
if (this.$route.query.code)
await this.$auth.setUserToken(this.$route.query.code)
},
data() { data() {
return { return {
theme: 'light', theme: 'light',
showPopup: false, showPopup: false,
} }
}, },
created() {
if (this.$route.query.code) this.$auth.setUserToken(this.$route.query.code)
},
beforeMount() { beforeMount() {
const theme = localStorage.getItem('data-theme') const theme = localStorage.getItem('data-theme')
? localStorage.getItem('data-theme') ? localStorage.getItem('data-theme')
@@ -441,6 +442,10 @@ export default {
} }
} }
.theme {
cursor: pointer;
}
.log-in-button { .log-in-button {
text-align: center; text-align: center;
padding: 8px 40px; padding: 8px 40px;
@@ -452,7 +457,6 @@ export default {
.user-actions-popup { .user-actions-popup {
position: relative; position: relative;
display: inline-block;
.popup-inner { .popup-inner {
width: 140px; width: 140px;
@@ -486,7 +490,7 @@ export default {
content: ''; content: '';
position: absolute; position: absolute;
top: 100%; top: 100%;
right: 90%; right: 80%;
border-width: 7px; border-width: 7px;
border-style: solid; border-style: solid;
border-color: var(--color-grey-2) transparent transparent border-color: var(--color-grey-2) transparent transparent

View File

@@ -158,4 +158,8 @@ export default {
** See https://nuxtjs.org/api/configuration-build/ ** See https://nuxtjs.org/api/configuration-build/
*/ */
build: {}, build: {},
loading: {
color: 'green',
height: '5px',
},
} }

View File

@@ -70,6 +70,9 @@
:categories="result.categories" :categories="result.categories"
:is-ad="index === -1" :is-ad="index === -1"
/> />
<div class="no-results" v-if="results.length === 0">
<p>No results found for your query!</p>
</div>
</div> </div>
<section v-if="pages.length > 1" class="search-bottom"> <section v-if="pages.length > 1" class="search-bottom">
<Multiselect <Multiselect
@@ -425,26 +428,7 @@ export default {
Multiselect, Multiselect,
SearchFilter, SearchFilter,
}, },
data() { async fetch() {
return {
query: '',
selectedVersions: [],
versions: [],
facets: [],
results: [],
pages: [],
currentPage: 1,
sortTypes: [
{ display: 'Relevance', name: 'relevance' },
{ display: 'Total Downloads', name: 'downloads' },
{ display: 'Newest', name: 'newest' },
{ display: 'Updated', name: 'updated' },
],
sortType: { display: 'Relevance', name: 'relevance' },
maxResults: 5,
}
},
async created() {
if (this.$route.query.q) this.query = this.$route.query.q if (this.$route.query.q) this.query = this.$route.query.q
if (this.$route.query.f) { if (this.$route.query.f) {
const facets = this.$route.query.f.split(',') const facets = this.$route.query.f.split(',')
@@ -465,6 +449,25 @@ export default {
await this.fillInitialVersions() await this.fillInitialVersions()
await this.onSearchChange(this.currentPage) await this.onSearchChange(this.currentPage)
}, },
data() {
return {
query: '',
selectedVersions: [],
versions: [],
facets: [],
results: [],
pages: [],
currentPage: 1,
sortTypes: [
{ display: 'Relevance', name: 'relevance' },
{ display: 'Total Downloads', name: 'downloads' },
{ display: 'Newest', name: 'newest' },
{ display: 'Updated', name: 'updated' },
],
sortType: { display: 'Relevance', name: 'relevance' },
maxResults: 5,
}
},
methods: { methods: {
async fillInitialVersions() { async fillInitialVersions() {
try { try {
@@ -721,6 +724,7 @@ export default {
margin-top: 1em; margin-top: 1em;
button { button {
cursor: pointer;
width: 100%; width: 100%;
padding: 5px 0; padding: 5px 0;
outline: none; outline: none;
@@ -812,6 +816,14 @@ select {
} }
} }
.no-results {
text-align: center;
padding: 20px 0;
font-size: 30px;
color: var(--color-text);
background-color: var(--color-grey-1);
}
.max-results { .max-results {
max-width: 80px; max-width: 80px;
} }
@@ -823,6 +835,7 @@ select {
.multiselect__tags, .multiselect__tags,
.multiselect__spinner { .multiselect__spinner {
background: var(--color-bg); background: var(--color-bg);
cursor: pointer;
} }
.multiselect__spinner::before, .multiselect__spinner::before,