Skip to content

Instantly share code, notes, and snippets.

<script>
getThreads();
</script>
// Get Threads Data
const getThreads = () => {
db.collection('threads')
.orderBy('created', 'desc')
.get().then(snapshot => setUpThreads(snapshot.docs));
}
// Logout
const logoutBtn = document.querySelector('#logout');
logoutBtn.addEventListener('click', () => auth.signOut());
// Listen for Auth Status Changes
auth.onAuthStateChanged(user => setUpUI(user));
// Real time update with Firebase for the Products
const getRealTimeUpdatesForProducts = (elementName, pageName) => {
...
db.collection('products').onSnapshot((doc) => {
let result = '';
doc.docs.forEach((doc) => {
...
const data = doc.data();
result += `
<div class="card-bg block block-strong inset">
// Uploading picture
function uploadImageToFirebaseStorage(elementName, fileName, img, edit) {
// // Create a reference for the storage, the folder and the filename
const storageRef = firebase.storage().ref('products/' + fileName);
// Upload the file and metadata
const uploadTask = storageRef.putString(img, 'base64');
// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// Move on the map and add marker to a chosen position
function moveOnTheMap(map, chosenPositionMarker) {
map.on("click", function (e) {
lat = e.latlng.lat;
lon = e.latlng.lng;
document.getElementById("shop-location").value = lat + " " + lon;
let redIcon = new L.Icon({
iconUrl: "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png",
shadowUrl: "https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",
let onSuccess = function (map, p) {
L.marker([p.coords.latitude, p.coords.longitude])
.addTo(map)
.bindPopup("Your current location.")
.openPopup();
map.setView([p.coords.latitude, p.coords.longitude], 14);
};
let map = null;
//For the edit-shop page, the map needs a different name
if (!map) map = L.map('newShopMap', {doubleClickZoom: false}).locate({setView: true, maxZoom: 12});
map.setView([35.40, 139.50], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const getProductInfoWithYahoo = (barcode) => {
try {
cordova.plugin.http.get('https://shopping.yahooapis.jp/ShoppingWebService/V3/itemSearch', {
appid: yahooApiKey,
jan_code: barcode
}, {}, function (response) {
const data = JSON.parse(response.data);
if (data && data.hits && data.hits.length) {
document.getElementById("product-name").value = data.hits[0].name;
document.getElementById("product-price").value = "¥" + data.hits[0].price;