Spaces:
Sleeping
Sleeping
Commit ·
3f6c1d4
1
Parent(s): f58484f
Revert Firebase config to original working state (twistedbrody-9d163)
Browse files- services/firebase.ts +27 -74
services/firebase.ts
CHANGED
|
@@ -13,14 +13,15 @@ import {
|
|
| 13 |
} from 'firebase/firestore';
|
| 14 |
import { DataItem } from '../types';
|
| 15 |
|
| 16 |
-
// Configuration
|
| 17 |
const firebaseConfig = {
|
| 18 |
-
apiKey: "
|
| 19 |
-
authDomain: "
|
| 20 |
-
projectId: "
|
| 21 |
-
storageBucket: "
|
| 22 |
-
messagingSenderId: "
|
| 23 |
-
appId: "1:
|
|
|
|
| 24 |
};
|
| 25 |
|
| 26 |
const app = initializeApp(firebaseConfig);
|
|
@@ -42,82 +43,34 @@ const cleanData = (data: any) => {
|
|
| 42 |
};
|
| 43 |
|
| 44 |
export const subscribeToItems = (callback: (items: DataItem[]) => void) => {
|
| 45 |
-
|
| 46 |
-
let voicesData: DataItem[] = [];
|
| 47 |
-
let neonItemsData: DataItem[] = [];
|
| 48 |
-
|
| 49 |
-
const updateAll = () => {
|
| 50 |
-
const combinedMap = new Map<string, DataItem>();
|
| 51 |
-
|
| 52 |
-
// Add folders
|
| 53 |
-
foldersData.forEach(item => combinedMap.set(item.id, item));
|
| 54 |
-
// Add voices
|
| 55 |
-
voicesData.forEach(item => combinedMap.set(item.id, item));
|
| 56 |
-
// Add neon items if any
|
| 57 |
-
neonItemsData.forEach(item => combinedMap.set(item.id, item));
|
| 58 |
-
|
| 59 |
-
callback(Array.from(combinedMap.values()));
|
| 60 |
-
};
|
| 61 |
-
|
| 62 |
-
// Subscribe to folders collection
|
| 63 |
-
const unsubFolders = onSnapshot(collection(db, 'folders'), (snapshot) => {
|
| 64 |
-
foldersData = snapshot.docs.map(doc => {
|
| 65 |
-
const data = doc.data();
|
| 66 |
-
return {
|
| 67 |
-
id: doc.id,
|
| 68 |
-
title: data.name || data.title || 'Carpeta',
|
| 69 |
-
summary: 'Carpeta',
|
| 70 |
-
content: '',
|
| 71 |
-
isFolder: true,
|
| 72 |
-
parentId: data.parentId || null,
|
| 73 |
-
tags: [],
|
| 74 |
-
categories: [],
|
| 75 |
-
createdAt: data.createdAt?.toMillis ? data.createdAt.toMillis() : Date.now(),
|
| 76 |
-
} as DataItem;
|
| 77 |
-
});
|
| 78 |
-
updateAll();
|
| 79 |
-
}, (err) => console.error("Error reading folders:", err));
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
voicesData = snapshot.docs.map(doc => {
|
| 84 |
const data = doc.data();
|
| 85 |
-
return {
|
| 86 |
-
id: doc.id,
|
| 87 |
-
title: data.title || 'Voz',
|
| 88 |
-
summary: '',
|
| 89 |
-
content: '',
|
| 90 |
-
visitUrl: data.url || data.visitUrl || '',
|
| 91 |
-
downloadUrl: data.downloadUrl || '',
|
| 92 |
-
isFolder: false,
|
| 93 |
-
parentId: data.folderId || data.parentId || null,
|
| 94 |
-
tags: data.tags || [],
|
| 95 |
-
categories: data.categories || [],
|
| 96 |
-
linkGroups: data.linkGroups || [],
|
| 97 |
-
createdAt: data.createdAt?.toMillis ? data.createdAt.toMillis() : Date.now(),
|
| 98 |
-
} as DataItem;
|
| 99 |
-
});
|
| 100 |
-
updateAll();
|
| 101 |
-
}, (err) => console.error("Error reading voices:", err));
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
return {
|
| 108 |
id: doc.id,
|
| 109 |
...data,
|
|
|
|
|
|
|
| 110 |
createdAt: data.createdAt?.toMillis ? data.createdAt.toMillis() : Date.now(),
|
|
|
|
| 111 |
} as DataItem;
|
| 112 |
});
|
| 113 |
-
|
| 114 |
-
}, (
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
unsubFolders();
|
| 118 |
-
unsubVoices();
|
| 119 |
-
unsubNeon();
|
| 120 |
-
};
|
| 121 |
};
|
| 122 |
|
| 123 |
export const addItem = async (item: Omit<DataItem, 'id' | 'createdAt'>): Promise<string> => {
|
|
|
|
| 13 |
} from 'firebase/firestore';
|
| 14 |
import { DataItem } from '../types';
|
| 15 |
|
| 16 |
+
// Configuration provided by user
|
| 17 |
const firebaseConfig = {
|
| 18 |
+
apiKey: "AIzaSyAH3jvbe0_QLzIuuv5kTMK8246HNvohvfE",
|
| 19 |
+
authDomain: "twistedbrody-9d163.firebaseapp.com",
|
| 20 |
+
projectId: "twistedbrody-9d163",
|
| 21 |
+
storageBucket: "twistedbrody-9d163.firebasestorage.app",
|
| 22 |
+
messagingSenderId: "733213514129",
|
| 23 |
+
appId: "1:733213514129:web:e9694684f5c3994ed06230",
|
| 24 |
+
measurementId: "G-N8TQ7MY42W"
|
| 25 |
};
|
| 26 |
|
| 27 |
const app = initializeApp(firebaseConfig);
|
|
|
|
| 43 |
};
|
| 44 |
|
| 45 |
export const subscribeToItems = (callback: (items: DataItem[]) => void) => {
|
| 46 |
+
const q = query(collection(db, COLLECTION_NAME), orderBy('createdAt', 'desc'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
return onSnapshot(q, (snapshot) => {
|
| 49 |
+
const items = snapshot.docs.map(doc => {
|
|
|
|
| 50 |
const data = doc.data();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
// Migrate old blocks without type to have 'text' type
|
| 53 |
+
let blocks = data.blocks;
|
| 54 |
+
if (blocks && Array.isArray(blocks)) {
|
| 55 |
+
blocks = blocks.map((block: any) => ({
|
| 56 |
+
...block,
|
| 57 |
+
type: block.type || 'text' // Default to 'text' if type is missing
|
| 58 |
+
}));
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
return {
|
| 62 |
id: doc.id,
|
| 63 |
...data,
|
| 64 |
+
blocks,
|
| 65 |
+
// Convert Firestore Timestamp to number (milliseconds) if necessary
|
| 66 |
createdAt: data.createdAt?.toMillis ? data.createdAt.toMillis() : Date.now(),
|
| 67 |
+
updatedAt: data.updatedAt?.toMillis ? data.updatedAt.toMillis() : (data.createdAt?.toMillis ? data.createdAt.toMillis() : Date.now()),
|
| 68 |
} as DataItem;
|
| 69 |
});
|
| 70 |
+
callback(items);
|
| 71 |
+
}, (error) => {
|
| 72 |
+
console.error("Error reading from Firestore:", error);
|
| 73 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
};
|
| 75 |
|
| 76 |
export const addItem = async (item: Omit<DataItem, 'id' | 'createdAt'>): Promise<string> => {
|