Skip to content

Commit

Permalink
search venue stage
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9a7i committed Oct 4, 2022
1 parent df63b40 commit 264d8a5
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 36 deletions.
13 changes: 4 additions & 9 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
const app = require('express')()
const bodyParser = require('body-parser')

const swarmRoutes = require("./swarm.js")

module.exports = { path: '/api', handler: app }

// Express Settings
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())


var timeout = require('connect-timeout');
app.use(timeout(1000*60*30));

// Swarm Route
app.use("/swarm", swarmRoutes)

// General Index Message
app.get('/' ,(req, res) => {
res.write('Hey!');
res.end()
})

module.exports = { path: '/api', handler: app }

app.get('/authenticate' ,(req, res) => {
res.write('Hey!');
res.end()
})
16 changes: 16 additions & 0 deletions components/Comps/Loading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div class="loading d-inline-block">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span class="visually-hidden">Loading...</span>
</div>
</template>

<script>
export default {
}
</script>

<style>
</style>
4 changes: 2 additions & 2 deletions components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<a href="/">Logo</a>
This is header section
</div>
<div class="col">
<button class="btn btn-danger" @click="logout">Log Out</button>
<div class="col text-end">
<button class="btn btn-danger btn-sm" @click="logout"><i class="bi bi-person-fill"></i> Log Out</button>
</div>
</div>

Expand Down
93 changes: 74 additions & 19 deletions components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,63 @@
<div class="row">
<div class="col">
<div class="card card-body border-0 shadow-sm">
<div class="">
<div class="form-check form-switch ps-0">
<div class="d-flex flex-column">
<div class="form-check form-switch py-2 ps-0 border-bottom">
<label class="form-check-label" for="flexSwitchEnableBot">Bot Enabled ?</label>
<div class="float-end">
<span :class="`spinner-border spinner-border-sm ${bot_enabled_spinner}`" role="status" aria-hidden="true"></span>
<span class="visually-hidden">Loading...</span>
<input class="form-check-input" type="checkbox" v-model="enabled_bot" role="switch" id="flexSwitchEnableBot" />
<CompsLoading v-if="configs.loading" />
<input class="form-check-input" type="checkbox" v-model="configs.enabled" role="switch" id="flexSwitchEnableBot" />
</div>

</div>

<div class="form-check form-switch ps-0">
<div class="form-check form-switch py-2 ps-0">
<label class="form-check-label" for="flexSwitchEnableAutoCheckIn">Auto Check In ?</label>
<div class="float-end">
<span :class="`spinner-border spinner-border-sm ${auto_check_in_enabled_spinner}`" role="status" aria-hidden="true"></span>
<span class="visually-hidden">Loading...</span>
<input class="form-check-input" type="checkbox" v-model="enabled_auto_checki_in" role="switch" id="flexSwitchEnableAutoCheckIn" />
<CompsLoading v-if="configs.checkins.loading" />
<input class="form-check-input" type="checkbox" v-model="configs.checkins.enabled" role="switch" id="flexSwitchEnableAutoCheckIn" />
</div>

</div>

<div class="venues">
<div class="add_venue d-block">
<div class="button_only mb-2 clearfix">
<button
class="btn btn-sm btn-success float-end"
type="button"
data-bs-toggle="collapse"
data-bs-target="#searchVenues"
>Add Venue</button>
</div>
<div class="search_area">
<div class="collapse" id="searchVenues">
<div class="card card-body">
<form class="d-flex">
<div class="flex-grow-1">

<input class="form-control" v-model="venue_search" list="venueOptions" id="inputVenueName" placeholder="Type to search...">
<datalist id="venueOptions">
<option value="San Francisco" />
<option value="New York" />
<option value="Seattle" />
<option value="Los Angeles" />
<option value="Chicago" />
</datalist>

</div>
<div class="flex-shrink-0 ps-2">
<button type="submit" class="btn btn-primary mb-3">Add</button>
</div>
</form>

</div>
</div>
</div>

</div>
<div class="venues_list"></div>
</div>
</div>
</div>
</div>
Expand All @@ -46,21 +83,40 @@ export default {
data(){
return {
user: null,
enabled_bot: false,
configs: {
enabled: false,
loading: true,
checkins: {
enabled: false,
loading: true,
venues: {},
}
},
venue_search: '',
bot_enabled_spinner: '',
enabled_auto_checki_in: false,
auto_check_in_enabled_spinner: '',
}
},
mounted() {
if(this.$auth.user?.user?.firstName){
this.user = this.$auth.user.user;
}

console.log('before mutlaq expierment')
this.$MFO_UTILS.setCheckInVenueInformation({id: 123})
console.log("mounted");
this.saveUser();
},
watch: {
enabled_bot: async function(val, oldVal) {
venue_search: async function(val){
if(val.length != 0){
//console.log(val);
let venue_name = await this.$MFO_UTILS.searchVenues(val);
console.log(venue_name[0]?.name);
}

},
'configs.enabled': async function(val, oldVal) {
this.bot_enabled_spinner = '';
console.log(val);
try {
Expand All @@ -71,7 +127,7 @@ export default {

this.bot_enabled_spinner = 'd-none';
},
enabled_auto_checki_in: async function(val, oldVal) {
'configs.checkins.enabled': async function(val, oldVal) {
this.auto_check_in_enabled_spinner = '';
console.log(val);
try {
Expand All @@ -83,7 +139,6 @@ export default {
this.auto_check_in_enabled_spinner = 'd-none';
}
},

methods: {
async saveUser() {
//console.log(this.$auth.strategy.token.get());
Expand All @@ -96,15 +151,15 @@ export default {
const userConfigs = await this.$MFO_UTILS.getConfigsFromFirebase();
if(userConfigs){
if(userConfigs?.enabled == true){
this.enabled_bot = true;
this.configs.enabled = true;
}

if(userConfigs?.settings?.auto_check_in?.enabled == true){
this.enabled_auto_checki_in = true;
if(userConfigs?.settings?.checkins?.enabled == true){
this.configs.checkins.enabled = true;
}

this.auto_check_in_enabled_spinner = 'd-none';
this.bot_enabled_spinner = 'd-none';
this.configs.loading = false;
this.configs.checkins.loading = false;
}
console.log(userConfigs)

Expand Down
5 changes: 1 addition & 4 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<template>
<div class="app">
<Header />
<main>
<main style="min-height:50vh;">
<nuxt/>
</main>
<Footer />
</div>
</template>

<script>
import Header from '~/components/Header.vue';
import Footer from '~/components/Footer.vue';
export default {
components: { Header, Footer }
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
async loginSwarm() {
console.log('before call');
await this.$auth.loginWith('social').catch(e => {
console.log('hello')
console.log('hello error login')
})
},
},
Expand Down
55 changes: 54 additions & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// * with help of Alexander Lichter, Apr 18, 2020, https://blog.lichter.io/posts/nuxt-api-call-organization-and-decoupling/
const axios = require('axios').default;

export default ($firebase, $auth) => () => ({

async createUserInFirebase() {
Expand Down Expand Up @@ -60,7 +62,7 @@ export default ($firebase, $auth) => () => ({
try {
const configsRef = $firebase.firestore.collection("configs").doc($auth.user.user.id);
await configsRef.update({settings: {
auto_check_in: {
checkins: {
enabled: value
}
} });
Expand All @@ -69,6 +71,57 @@ export default ($firebase, $auth) => () => ({
console.log(error);
return false;
}
},

async searchVenues(name){
try {
let venues_result = await axios.get('https://api.foursquare.com/v3/places/search', {
params: {
near: 'Saudi Arabia',
query: name
},
headers:{
Authorization: 'fsq3mvJJUXXc2bwnfvTp3/YZfKabrAfiORz2rTyxJHTwEPQ='
}
});

if(venues_result.data.results.length > 0){
return venues_result.data.results;
}

return {};
} catch (error) {
console.log(error);
return false;
}



},

async setCheckInVenueInformation(venue_info){
try {
let venue_id = venue_info.id

let venue_settings = {
settings: {
checkins: {
venues: {}
}
}
};

venue_settings.settings.checkins.venues[venue_id] = {
id: 123
}

const configsRef = $firebase.firestore.collection("configs").doc($auth.user.user.id);
await configsRef.update(venue_settings);
return true;
} catch (error) {
console.log(error);
return false;
}
}


Expand Down

0 comments on commit 264d8a5

Please sign in to comment.