mirror of
https://github.com/romancm/gamebrary
synced 2024-11-23 19:53:14 +00:00
added global game search
This commit is contained in:
parent
7eb8dd8b57
commit
bfdd937a79
4 changed files with 90 additions and 18 deletions
|
@ -36,16 +36,20 @@ exports.customSearch = functions.https.onRequest((req, res) => {
|
||||||
? `limit ${req.query.limit};`
|
? `limit ${req.query.limit};`
|
||||||
: 'limit 50;';
|
: 'limit 50;';
|
||||||
|
|
||||||
|
const search = req.query.searchText
|
||||||
|
? `search "${req.query.searchText}";`
|
||||||
|
: '';
|
||||||
|
|
||||||
const fields = req.query.fields
|
const fields = req.query.fields
|
||||||
? `fields ${req.query.fields};`
|
? `fields ${req.query.fields};`
|
||||||
: 'fields id,name,slug,rating,name,cover.image_id,first_release_date;';
|
: 'fields id,name,slug,rating,name,cover.image_id,first_release_date;';
|
||||||
|
|
||||||
const data = `
|
const data = `
|
||||||
|
${search}
|
||||||
${fields}
|
${fields}
|
||||||
${sort}
|
${sort}
|
||||||
${limit}
|
${limit}
|
||||||
${query}
|
${query}`;
|
||||||
`;
|
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
url: 'https://api.igdb.com/v4/games',
|
url: 'https://api.igdb.com/v4/games',
|
||||||
|
@ -122,7 +126,7 @@ exports.refreshToken = functions.pubsub.schedule('0 0 * * 0')
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.platforms = functions.https.onRequest((req, res) => {
|
exports.platforms = functions.https.onRequest((req, res) => {
|
||||||
res.set('Access-Control-Allow-Origin', "*")
|
res.set('Access-Control-Allow-Origin', "*");
|
||||||
|
|
||||||
const { token } = req.query;
|
const { token } = req.query;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<portal-target name="dock" multiple />
|
<portal-target name="dock" multiple />
|
||||||
|
|
||||||
<!-- <global-search /> -->
|
<global-search />
|
||||||
|
|
||||||
<sidebar />
|
<sidebar />
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -34,13 +34,13 @@
|
||||||
import { mapState, mapGetters } from 'vuex';
|
import { mapState, mapGetters } from 'vuex';
|
||||||
import PinnedBoards from '@/components/Board/PinnedBoards';
|
import PinnedBoards from '@/components/Board/PinnedBoards';
|
||||||
import Sidebar from '@/components/Sidebar';
|
import Sidebar from '@/components/Sidebar';
|
||||||
// import GlobalSearch from '@/components/GlobalSearch';
|
import GlobalSearch from '@/components/GlobalSearch';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
PinnedBoards,
|
PinnedBoards,
|
||||||
Sidebar,
|
Sidebar,
|
||||||
// GlobalSearch,
|
GlobalSearch,
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
|
|
@ -1,28 +1,87 @@
|
||||||
<template lang="html">
|
<template lang="html">
|
||||||
<div class="global-search">
|
<div class="global-search">
|
||||||
<b-form-input
|
<b-button v-b-toggle.global-search>
|
||||||
v-model="searchText"
|
<i class="fas fa-search fa-fw" aria-hidden />
|
||||||
type="search"
|
</b-button>
|
||||||
debounce="500"
|
|
||||||
:placeholder="$t('board.addGame.inputPlaceholder')"
|
|
||||||
@update="search"
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
<b-sidebar
|
||||||
|
id="global-search"
|
||||||
|
title="Sidebar"
|
||||||
|
shadow
|
||||||
|
backdrop
|
||||||
|
bg-variant="dark"
|
||||||
|
text-variant="white"
|
||||||
|
right
|
||||||
|
header-class="px-2 pt-2 d-flex align-items-center justify-content-between"
|
||||||
|
>
|
||||||
|
<template #header="{ hide }">
|
||||||
|
<h5 class="mb-0 ml-2">
|
||||||
|
Game search
|
||||||
|
</h5>
|
||||||
|
|
||||||
|
<b-button
|
||||||
|
class="align-self-baseline"
|
||||||
|
@click="hide"
|
||||||
|
>
|
||||||
|
<i class="fas fa-times fa-fw" aria-hidden />
|
||||||
|
</b-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="px-3 py-2">
|
||||||
|
<b-form-input
|
||||||
|
v-model="searchText"
|
||||||
|
type="search"
|
||||||
|
autofocus
|
||||||
|
debounce="500"
|
||||||
|
class="mb-4"
|
||||||
|
:placeholder="$t('board.addGame.inputPlaceholder')"
|
||||||
|
@update="search"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<b-list-group
|
||||||
|
v-for="{ id } in searchResults"
|
||||||
|
:key="id"
|
||||||
|
@click="openGame(id)"
|
||||||
|
>
|
||||||
|
<game-card-search
|
||||||
|
:game-id="id"
|
||||||
|
class="mb-2"
|
||||||
|
/>
|
||||||
|
</b-list-group>
|
||||||
|
</div>
|
||||||
|
</b-sidebar>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import GameCardSearch from '@/components/GameCards/GameCardSearch';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
GameCardSearch,
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
searchText: '',
|
searchText: '',
|
||||||
|
searchResults: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
search(text) {
|
openGame(gameId) {
|
||||||
console.log(text);
|
this.$store.commit('SET_GAME_MODAL_DATA', { gameId });
|
||||||
this.$store.dispatch('CUSTOM_SEARCH', text);
|
this.$bvModal.show('game-modal');
|
||||||
|
},
|
||||||
|
|
||||||
|
async search(searchText) {
|
||||||
|
if (!searchText) {
|
||||||
|
this.searchResults = [];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.searchResults = await this.$store.dispatch('CUSTOM_SEARCH', { searchText });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -438,9 +438,18 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
CUSTOM_SEARCH({ commit, state }, { platforms, sortQuery }) {
|
CUSTOM_SEARCH({ commit, state }, { platforms = '', sortQuery = '', searchText = '' }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.get(`${API_BASE}/customSearch?platforms=${platforms}&sortQuery=${sortQuery}&token=${state.twitchToken.access_token}`)
|
const params = {
|
||||||
|
token: state.twitchToken.access_token,
|
||||||
|
platforms,
|
||||||
|
sortQuery,
|
||||||
|
searchText,
|
||||||
|
};
|
||||||
|
|
||||||
|
const query = new URLSearchParams(params).toString();
|
||||||
|
|
||||||
|
axios.get(`${API_BASE}/customSearch?${query}`)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
commit('CACHE_GAME_DATA', data);
|
commit('CACHE_GAME_DATA', data);
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
|
Loading…
Reference in a new issue