Skip to content

Commit

Permalink
Use new proxy + axios for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherJennings committed Jan 24, 2020
1 parent 7008fd5 commit 804820e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 153 deletions.
74 changes: 35 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"deploy": "npm run build && deploy.sh"
},
"dependencies": {
"axios": "^0.19.2",
"bulma": "^0.7.2",
"unsplash-js": "^4.8.0",
"vue": "^2.5.21",
"vue-resize": "^0.4.5"
},
Expand Down
15 changes: 1 addition & 14 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
id="app"
v-if="loaded"
>

<not-configured v-if="!$Unsplash.Instance" />

<preview-selected
v-else-if="photo"
v-if="photo"
:disabled="disabled"
:photo="photo"
@clear-photo="clearPhoto()"
Expand All @@ -30,7 +27,6 @@
</template>

<script>
import NotConfigured from './components/not-configured'
import PreviewSelected from './components/preview-selected'
import UnsplashSelector from './components/unsplash-selector'
Expand All @@ -46,7 +42,6 @@ export default {
}
},
components: {
NotConfigured,
PreviewSelected,
UnsplashSelector,
},
Expand Down Expand Up @@ -88,14 +83,6 @@ export default {
}
this.disabled = this.element.disabled
// Instantiate Unsplash API
if(this.element.config && this.element.config.accessKey && this.element.config.secretKey) {
this.$Unsplash.createInstance({
applicationId: this.element.config.accessKey,
secret: this.element.config.secretKey
})
}
this.loaded = true
this.$CustomElement.updateSize()
})
Expand Down
75 changes: 0 additions & 75 deletions src/components/not-configured.vue

This file was deleted.

13 changes: 5 additions & 8 deletions src/components/unsplash-selector-search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</template>

<script>
import { toJson } from 'unsplash-js'
import unsplash from '../unsplashApi'
import UnsplashSelectorResults from './unsplash-selector-results'
export default {
Expand All @@ -53,12 +53,9 @@ export default {
methods: {
searchPhotos(page) {
this.nextPageToLoad = page ? page : this.nextPageToLoad
const unsplash = this.$Unsplash.Instance
if(this.searchTerm && unsplash) {
unsplash.search.photos(this.searchTerm, this.nextPageToLoad)
.then(toJson)
.then(json => {
this.searchResponse = json
if(this.searchTerm) {
unsplash.searchPhotos(this.searchTerm, this.nextPageToLoad).then(response =>{
this.searchResponse = response.data
if(this.searchResults === null) {
this.searchResults = this.searchResponse.results
} else {
Expand All @@ -74,7 +71,7 @@ export default {
},
selectPhoto(photo) {
// Tell Unsplash that the photo was selected
this.$Unsplash.Instance.photos.downloadPhoto(photo)
unsplash.trackDownload(photo.id)
this.$emit('select-photo', photo)
},
},
Expand Down
2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import VueMasonry from 'vue-masonry-css'
import VueResize from 'vue-resize'
import App from './App.vue'
import KenticoCloudCustomElement from './plugins/kentico-cloud-custom-element'
import Unsplash from './plugins/unsplash'

import 'bulma/css/bulma.css'
import 'vue-resize/dist/vue-resize.css'

Vue.use(VueMasonry);
Vue.use(VueResize);
Vue.use(KenticoCloudCustomElement)
Vue.use(Unsplash)

Vue.config.productionTip = false

Expand Down
14 changes: 0 additions & 14 deletions src/plugins/unsplash/index.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/unsplashApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios'

const _baseUrl = "https://kontentunsplash.azurewebsites.net"

export default {
async searchPhotos(keyword, page) {
const url = `${_baseUrl}/search/photos?query=${encodeURIComponent(keyword)}&page=${page}`
return await axios.get(url);
},
trackDownload(id) {
const url = `${_baseUrl}/photos/${id}/download`
axios.get(url);
}
}

0 comments on commit 804820e

Please sign in to comment.