Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
Browse files Browse the repository at this point in the history
…dxp-component/#140-centralizedoms
  • Loading branch information
amansinghbais committed Sep 22, 2023
2 parents 484a920 + 444d762 commit 8c3b940
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 61 deletions.
17 changes: 10 additions & 7 deletions src/components/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ export default defineComponent({
try {
await context.login({ token, oms })

// initialising and connecting firebase app for notification support
await initialiseFirebaseApp(
noitificationContext.appFirebaseConfig,
noitificationContext.appFirebaseVapidKey,
noitificationContext.storeClientRegistrationToken,
noitificationContext.addNotification,
)
// check if firebase configurations are there
if (noitificationContext.appFirebaseConfig) {
// initialising and connecting firebase app for notification support
await initialiseFirebaseApp(
noitificationContext.appFirebaseConfig,
noitificationContext.appFirebaseVapidKey,
noitificationContext.storeClientRegistrationToken,
noitificationContext.addNotification,
)
}

this.router.push('/')
} catch (error) {
Expand Down
52 changes: 0 additions & 52 deletions src/components/ShopifyImg.ts

This file was deleted.

47 changes: 47 additions & 0 deletions src/components/ShopifyImg.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<img :src="imageUrl" />
</template>

<script setup lang="ts">
import { onMounted, onUpdated, ref } from "vue";
import { shopifyImgContext as context } from "../index";
const props = defineProps(['src', 'size']);
const imageUrl = ref(context.defaultImgUrl);
const checkIfImageExists = (src: string) => {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(true);
img.onerror = () => reject(false);
img.src = src;
})
};
const prepareImgUrl = (src: string, size?: string) => {
// return original size if no size is given
if (!size) return src
// remove any current image size then add the new image size
return src
.replace(/_(pico|icon|thumb|small|compact|medium|large|grande|original|1024x1024|2048x2048|master)+\./g, '.')
.replace(/\.jpg|\.png|\.gif|\.jpeg/g, function (match) {
return '_' + size + match;
})
};
const setImageUrl = () => {
if (props.src) {
const src: string = prepareImgUrl(props.src, props.size)
checkIfImageExists(src).then(() => imageUrl.value = src)
}
};
onMounted(() => {
setImageUrl();
});
onUpdated(() => {
setImageUrl();
});
</script>
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ import '@ionic/vue/css/display.css';
export { default as ProductIdentifier } from "./ProductIdentifier.vue";
export { default as LanguageSwitcher } from './LanguageSwitcher.vue';
export { default as OmsInstanceNavigator } from './OmsInstanceNavigator.vue'
export { default as ShopifyImg } from './ShopifyImg.vue';
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ declare var process: any;
import { createPinia } from "pinia";
import { useProductIdentificationStore } from "./store/productIdentification";
import { useAuthStore } from "./store/auth";
import { LanguageSwitcher, OmsInstanceNavigator, ProductIdentifier } from "./components";
import { LanguageSwitcher, OmsInstanceNavigator, ProductIdentifier, ShopifyImg } from "./components";
import Login from "./components/Login";
import ShopifyImg from "./components/ShopifyImg";
import { goToOms } from "./utils";
import { initialiseFirebaseApp } from "./utils/firebase"
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
Expand Down

0 comments on commit 8c3b940

Please sign in to comment.