Skip to content

Commit

Permalink
feat(firebase): export firebase service
Browse files Browse the repository at this point in the history
  • Loading branch information
realappie committed Nov 9, 2021
1 parent a232e4f commit 2ca1af7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/components/picker-customer-logo/picker-customer-logo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { getDownloadURL } from '@firebase/storage';
import { Component, Host, h, Prop, State } from '@stencil/core';
import { ref } from 'firebase/storage';
import { Component, h, Host, Prop, State } from '@stencil/core';
import { firebaseServiceInstance } from '../../firebase';

@Component({
Expand All @@ -27,7 +25,7 @@ export class PickerCustomerLogo {
private async loadImageSrc() {
try {
console.log(`[eva-picker-customer-logo] getting customer logo for ${this.customerName} with logoPath ${this.logoPath}`);
this.logoSrc = await getDownloadURL(ref(firebaseServiceInstance.storage, this.logoPath));
this.logoSrc = await firebaseServiceInstance.getImageUrl(this.logoPath);
} catch (error) {
console.error(`[eva-picker-customer-logo] error getting customer logo for ${this.customerName}`, error);
}
Expand Down
6 changes: 6 additions & 0 deletions src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { collection, getDoc, getDocs, getFirestore } from "@firebase/firestore";
import { initializeApp } from "firebase/app";
import { getStorage } from "firebase/storage";
import { BaseEnvironment, SummarisedViewCustomer, ExtendedViewCustomer } from "./typings";
import { getDownloadURL, ref } from '@firebase/storage';

class FirebaseService {


app = initializeApp({
apiKey: "AIzaSyD51D-mGBu-wAOxckCZO2-dk5IRjrYhNlI",
authDomain: "eva-customer-manager.firebaseapp.com",
Expand Down Expand Up @@ -87,6 +89,10 @@ class FirebaseService {

return extendedViewCustomer;
}

getImageUrl(logoPath: string) {
return getDownloadURL(ref(firebaseServiceInstance.storage, logoPath));
}
}

export const firebaseServiceInstance = new FirebaseService();
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './components';
export * from './typings';
export {firebaseServiceInstance} from './firebase';

0 comments on commit 2ca1af7

Please sign in to comment.