diff --git a/.env b/.env new file mode 100644 index 0000000..204ddb0 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VUE_APP_EXCHANGE_RATES_API=https://api.exchangeratesapi.io/latest?base= diff --git a/package.json b/package.json index 0b5f203..7c828d6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@tailwindcss/postcss7-compat": "^2.0.2", "autoprefixer": "^9", + "axios": "^0.21.1", "core-js": "^3.6.5", "postcss": "^7", "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2", diff --git a/src/App.vue b/src/App.vue index 60947f8..537aead 100644 --- a/src/App.vue +++ b/src/App.vue @@ -17,11 +17,15 @@ -moz-osx-font-smoothing: grayscale; } -html, body, #app { +html{ width: 100%; height: 100%; } +html { + @apply bg-blue-ady; +} + .noSelect { -webkit-touch-callout: none; -webkit-user-select: none; diff --git a/src/assets/flags/aud.svg b/src/assets/flags/aud.svg new file mode 100644 index 0000000..6c4adba --- /dev/null +++ b/src/assets/flags/aud.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/bgn.svg b/src/assets/flags/bgn.svg new file mode 100644 index 0000000..8fd7a70 --- /dev/null +++ b/src/assets/flags/bgn.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/brl.svg b/src/assets/flags/brl.svg new file mode 100644 index 0000000..cf13a7d --- /dev/null +++ b/src/assets/flags/brl.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/cad.svg b/src/assets/flags/cad.svg new file mode 100644 index 0000000..850fcca --- /dev/null +++ b/src/assets/flags/cad.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/chf.svg b/src/assets/flags/chf.svg new file mode 100644 index 0000000..a142505 --- /dev/null +++ b/src/assets/flags/chf.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/cny.svg b/src/assets/flags/cny.svg new file mode 100644 index 0000000..1bf22dd --- /dev/null +++ b/src/assets/flags/cny.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/assets/flags/czk.svg b/src/assets/flags/czk.svg new file mode 100644 index 0000000..f813ac7 --- /dev/null +++ b/src/assets/flags/czk.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/dkk.svg b/src/assets/flags/dkk.svg new file mode 100644 index 0000000..847b9d0 --- /dev/null +++ b/src/assets/flags/dkk.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/eur.svg b/src/assets/flags/eur.svg new file mode 100644 index 0000000..a625614 --- /dev/null +++ b/src/assets/flags/eur.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/gbp.svg b/src/assets/flags/gbp.svg new file mode 100644 index 0000000..b94d248 --- /dev/null +++ b/src/assets/flags/gbp.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/hkd.svg b/src/assets/flags/hkd.svg new file mode 100644 index 0000000..7a1bacc --- /dev/null +++ b/src/assets/flags/hkd.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/hrk.svg b/src/assets/flags/hrk.svg new file mode 100644 index 0000000..60e8232 --- /dev/null +++ b/src/assets/flags/hrk.svg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/huf.svg b/src/assets/flags/huf.svg new file mode 100644 index 0000000..508472c --- /dev/null +++ b/src/assets/flags/huf.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/idr.svg b/src/assets/flags/idr.svg new file mode 100644 index 0000000..3d7cdc6 --- /dev/null +++ b/src/assets/flags/idr.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/assets/flags/ils.svg b/src/assets/flags/ils.svg new file mode 100644 index 0000000..68244c5 --- /dev/null +++ b/src/assets/flags/ils.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/assets/flags/inr.svg b/src/assets/flags/inr.svg new file mode 100644 index 0000000..95ff438 --- /dev/null +++ b/src/assets/flags/inr.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/assets/flags/isk.png b/src/assets/flags/isk.png new file mode 100644 index 0000000..94173f8 Binary files /dev/null and b/src/assets/flags/isk.png differ diff --git a/src/assets/flags/jpy.svg b/src/assets/flags/jpy.svg new file mode 100644 index 0000000..0988dc9 --- /dev/null +++ b/src/assets/flags/jpy.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/assets/flags/krw.svg b/src/assets/flags/krw.svg new file mode 100644 index 0000000..9593bfc --- /dev/null +++ b/src/assets/flags/krw.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/mxn.svg b/src/assets/flags/mxn.svg new file mode 100644 index 0000000..d9bff6b --- /dev/null +++ b/src/assets/flags/mxn.svg @@ -0,0 +1,765 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/myr.svg b/src/assets/flags/myr.svg new file mode 100644 index 0000000..2dbdd58 --- /dev/null +++ b/src/assets/flags/myr.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/assets/flags/nok.svg b/src/assets/flags/nok.svg new file mode 100644 index 0000000..aa39fc0 --- /dev/null +++ b/src/assets/flags/nok.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/nzd.svg b/src/assets/flags/nzd.svg new file mode 100644 index 0000000..19e8c3b --- /dev/null +++ b/src/assets/flags/nzd.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/php.svg b/src/assets/flags/php.svg new file mode 100644 index 0000000..2d311f3 --- /dev/null +++ b/src/assets/flags/php.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/assets/flags/pln.svg b/src/assets/flags/pln.svg new file mode 100644 index 0000000..68e261d --- /dev/null +++ b/src/assets/flags/pln.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/assets/flags/ron.svg b/src/assets/flags/ron.svg new file mode 100644 index 0000000..128d19c --- /dev/null +++ b/src/assets/flags/ron.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/rub.svg b/src/assets/flags/rub.svg new file mode 100644 index 0000000..0a0e4ff --- /dev/null +++ b/src/assets/flags/rub.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/sek.svg b/src/assets/flags/sek.svg new file mode 100644 index 0000000..8023302 --- /dev/null +++ b/src/assets/flags/sek.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/flags/sgd.svg b/src/assets/flags/sgd.svg new file mode 100644 index 0000000..ecfe689 --- /dev/null +++ b/src/assets/flags/sgd.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/flags/thb.svg b/src/assets/flags/thb.svg new file mode 100644 index 0000000..ed28591 --- /dev/null +++ b/src/assets/flags/thb.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/assets/flags/try.svg b/src/assets/flags/try.svg new file mode 100644 index 0000000..8b123ed --- /dev/null +++ b/src/assets/flags/try.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/flags/usd.svg b/src/assets/flags/usd.svg new file mode 100644 index 0000000..3eeae53 --- /dev/null +++ b/src/assets/flags/usd.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/flags/zar.svg b/src/assets/flags/zar.svg new file mode 100644 index 0000000..1d97587 --- /dev/null +++ b/src/assets/flags/zar.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/assets/misc/spinner.svg b/src/assets/misc/spinner.svg new file mode 100644 index 0000000..e89b32d --- /dev/null +++ b/src/assets/misc/spinner.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/assets/tailwind.css b/src/assets/tailwind.css index ebc487e..c7d6bb7 100644 --- a/src/assets/tailwind.css +++ b/src/assets/tailwind.css @@ -24,56 +24,6 @@ .description { @apply text-white-ady; } - - .sort-dropdown { - @apply w-auto; - @apply h-56; - @apply mt-4; - @apply overflow-scroll; - @apply rounded-b-md; - @apply shadow-2xl; - @apply absolute; - @apply bg-white; - @apply z-10; - } - - .sort-dropdown-option { - @apply cursor-pointer; - @apply block; - @apply py-4; - @apply px-8; - @apply text-base; - @apply leading-5; - @apply text-gray-700; - @apply border-gray-300; - } - - .sort-dropdown-option:hover, .sort-dropdown-option:focus { - @apply bg-gray-100; - @apply text-gray-900; - @apply outline-none; - } - - .settings-button-choice { - @apply rounded-lg; - @apply py-2; - @apply w-auto; - @apply cursor-pointer; - @apply text-3xl; - @apply text-center; - } - - @screen sm { - .settings-button-choice { - @apply text-xl; - } - } - - @screen md { - .settings-button-choice { - @apply text-3xl; - } - } } @tailwind utilities; diff --git a/src/components/CurrencyConverter/CurrencyConverter.vue b/src/components/CurrencyConverter/CurrencyConverter.vue index f4af0df..f20406e 100644 --- a/src/components/CurrencyConverter/CurrencyConverter.vue +++ b/src/components/CurrencyConverter/CurrencyConverter.vue @@ -1,12 +1,30 @@ @@ -15,11 +33,90 @@ import Currency from '@/components/CurrencyConverter/components/Currency.vue'; import CurrencyRatio from '@/components/CurrencyConverter/components/CurrencyRatio.vue'; +/* eslint-disable max-len */ +/* eslint-disable prefer-destructuring */ + export default { name: 'CurrencyConverter', components: { Currency, CurrencyRatio, }, + props: { + currencies: { + type: Array, + }, + }, + data() { + return { + firstCurrency: this.currencies[0], + secondCurrency: this.currencies[1], + firstCurrencyAmount: 1, + secondCurrencyAmount: 0, + firstAgainstSecondCurrency: 0, + secondAgainstFirstCurrency: 0, + firstCurrencyCausedChange: false, + secondCurrencyCausedChange: false, + }; + }, + methods: { + async setCurrencyRates() { + if (this.firstCurrency === this.secondCurrency) { + this.firstAgainstSecondCurrency = 1; + this.secondAgainstFirstCurrency = 1; + return; + } + const rates = await this.$store.getters.getRates; + if (!rates[this.firstCurrency] && !rates[this.secondCurrency]) { + await this.$store.dispatch('fetchRate', this.firstCurrency); + await this.$store.dispatch('fetchRate', this.secondCurrency); + } + if (rates[this.firstCurrency]) { + this.firstAgainstSecondCurrency = rates[this.firstCurrency].rates[this.secondCurrency]; + this.secondAgainstFirstCurrency = 1 / this.firstAgainstSecondCurrency; + } else { + this.secondAgainstFirstCurrency = rates[this.secondCurrency].rates[this.firstCurrency]; + this.firstAgainstSecondCurrency = 1 / this.secondAgainstFirstCurrency; + } + }, + async firstCurrencyChanged(...args) { + this.firstCurrency = args[0]; + await this.setCurrencyRates(); + this.setSecondCurrencyAmount(); + this.secondCurrencyCausedChange = false; + this.firstCurrencyCausedChange = true; + }, + async firstCurrencyAmountChanged(...args) { + const newAmount = args[0]; + this.secondCurrencyCausedChange = false; + this.firstCurrencyCausedChange = true; + this.firstCurrencyAmount = parseFloat(newAmount); + this.setSecondCurrencyAmount(); + }, + setSecondCurrencyAmount() { + this.secondCurrencyAmount = parseFloat((this.firstCurrencyAmount * this.firstAgainstSecondCurrency).toFixed(2)); + }, + async secondCurrencyChanged(...args) { + this.secondCurrency = args[0]; + await this.setCurrencyRates(); + this.setFirstCurrencyAmount(); + this.firstCurrencyCausedChange = false; + this.secondCurrencyCausedChange = true; + }, + async secondCurrencyAmountChanged(...args) { + const newAmount = args[0]; + this.firstCurrencyCausedChange = false; + this.secondCurrencyCausedChange = true; + this.secondCurrencyAmount = parseFloat(newAmount); + this.setFirstCurrencyAmount(); + }, + setFirstCurrencyAmount() { + this.firstCurrencyAmount = parseFloat((this.secondCurrencyAmount * this.secondAgainstFirstCurrency).toFixed(2)); + }, + }, + async beforeMount() { + await this.setCurrencyRates(); + this.setSecondCurrencyAmount(); + }, }; diff --git a/src/components/CurrencyConverter/components/Currency.vue b/src/components/CurrencyConverter/components/Currency.vue index 06dfc1f..a50f310 100644 --- a/src/components/CurrencyConverter/components/Currency.vue +++ b/src/components/CurrencyConverter/components/Currency.vue @@ -1,10 +1,18 @@ @@ -12,6 +20,39 @@ diff --git a/src/components/CurrencyConverter/components/CurrencyRatio.vue b/src/components/CurrencyConverter/components/CurrencyRatio.vue index f4a6c45..1ab92b8 100644 --- a/src/components/CurrencyConverter/components/CurrencyRatio.vue +++ b/src/components/CurrencyConverter/components/CurrencyRatio.vue @@ -1,5 +1,29 @@ + + diff --git a/src/components/shared/Dropdown.vue b/src/components/shared/Dropdown.vue index 693f463..4250a0e 100644 --- a/src/components/shared/Dropdown.vue +++ b/src/components/shared/Dropdown.vue @@ -1,23 +1,26 @@ + + diff --git a/src/components/shared/TextInput.vue b/src/components/shared/TextInput.vue index 973078d..8631339 100644 --- a/src/components/shared/TextInput.vue +++ b/src/components/shared/TextInput.vue @@ -1,11 +1,64 @@ + + diff --git a/src/main.js b/src/main.js index 3621783..c87b864 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,5 @@ import Vue from 'vue'; +import Axios from 'axios'; import App from './App.vue'; import router from './router'; import store from './store'; @@ -6,6 +7,8 @@ import './assets/tailwind.css'; Vue.config.productionTip = false; +Vue.prototype.$http = Axios; + new Vue({ router, store, diff --git a/src/router/index.js b/src/router/index.js index 41d2d27..b129fea 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,7 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; import Home from '../views/Home.vue'; +import PageNotFound from '../views/PageNotFound.vue'; Vue.use(VueRouter); @@ -10,6 +11,11 @@ const routes = [ name: 'Home', component: Home, }, + { + path: '*', + name: 'PageNotFound', + component: PageNotFound, + }, ]; const router = new VueRouter({ diff --git a/src/store/index.js b/src/store/index.js index 9ea7685..bb01dc7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,9 +1,11 @@ import Vue from 'vue'; import Vuex from 'vuex'; +import CurrencyExchange from './modules/CurrencyExchange'; Vue.use(Vuex); export default new Vuex.Store({ + strict: true, state: { }, mutations: { @@ -11,5 +13,6 @@ export default new Vuex.Store({ actions: { }, modules: { + CurrencyExchange, }, }); diff --git a/src/store/modules/CurrencyExchange.js b/src/store/modules/CurrencyExchange.js new file mode 100644 index 0000000..6263eb6 --- /dev/null +++ b/src/store/modules/CurrencyExchange.js @@ -0,0 +1,33 @@ +import Axios from 'axios'; + +/* eslint-disable */ + +const state = { + rates: {}, +}; + +const getters = { + getRates(state) { + return state.rates; + }, +}; + +const mutations = { + fetchRate(state, { currency, exchangeRate }) { + state.rates[currency] = exchangeRate; + }, +}; + +const actions = { + async fetchRate(state, currency) { + const response = await Axios.get(process.env.VUE_APP_EXCHANGE_RATES_API + currency); + await state.commit('fetchRate', { currency, exchangeRate: response.data }); + }, +}; + +export default { + state, + getters, + mutations, + actions, +}; diff --git a/src/views/Home.vue b/src/views/Home.vue index 37ac11b..1605601 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,26 +1,41 @@ + + diff --git a/src/views/PageNotFound.vue b/src/views/PageNotFound.vue new file mode 100644 index 0000000..184e447 --- /dev/null +++ b/src/views/PageNotFound.vue @@ -0,0 +1,9 @@ + diff --git a/yarn.lock b/yarn.lock index 0070b88..6c831bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2283,6 +2283,13 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== + dependencies: + follow-redirects "^1.10.0" + babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -5074,7 +5081,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@^1.0.0: +follow-redirects@^1.0.0, follow-redirects@^1.10.0: version "1.13.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147" integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==