Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 184 additions & 5 deletions src/Firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ async function loginWithGoogle() {
"uid": uid_str,
"coins": 0,
"rooms": ["Gray"],
"decorations": []
"decorations": [],
"lastLogin": Date.now(),
// "friends": [],
// "requests": [],
// "email": ""
});
}
catch (e) {
Expand All @@ -60,7 +64,15 @@ async function loginWithGoogle() {
// @ts-ignore
rooms: doc.data().rooms,
// @ts-ignore
decorations: doc.data().decorations
decorations: doc.data().decorations,
// @ts-ignore
lastLogin: doc.data().lastLogin,
// // @ts-ignore
// friends: doc.data().friends,
// // @ts-ignore
// requests: doc.data().requests,
// // @ts-ignore
// email: doc.data().email
});
}
}
Expand Down Expand Up @@ -117,7 +129,11 @@ async function addActivity(activity, date, length) {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins + Math.round(length/1000),
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});
}
catch (e) {
Expand Down Expand Up @@ -160,18 +176,181 @@ async function buyRoom(room, price) {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins - price,
"rooms": rooms,
"decorations": get(UserInfoStore).decorations
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email

});
}
catch (e) {
console.log(e);
}
}
/**
* @param {string} decoration
* @param {number} price
*/
async function buyDecoration(decoration, price) {
try {
let decorations = get(UserInfoStore).rooms;
decorations.push(decoration);
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins - price,
"rooms": get(UserInfoStore).rooms,
"decorations": decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});
}
catch (e) {
console.log(e);
}
}

/**
*
* @param {number} newTime
*/
async function addLastLogin(newTime){
try{
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins,
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations,
"lastLogin": newTime,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});
}
catch (e){
console.log(e);
}
}
/*
Friend list func

Add (accept)
Delete
Decline
Send

*/

/**
*
* @param {any} aFriend
*/
async function addFriend(aFriend){
try{
// friends.push(aFriend);
// requests.remove(aFriend);
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins,
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});


// Add friends on the sender side
}
catch (e){
console.log(e);
}
}

/**
*
* @param {any} delFriend
*/
async function deleteFriend(delFriend){
try{
// friends.remove(delFriend);
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins,
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});

// Remove friends on the receiver side
}
catch (e){
console.log(e);
}
}

/**
*
* @param {any} declFriend
*/
async function declineFriend(declFriend){
try{
// requests.remove(declFriend);
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins,
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});

// Remove friends on the receiver side
}
catch (e){
console.log(e);
}
}

/**
*
* @param {any} reqFriend
*/
async function sendFriendRequest(reqFriend){
try{
//On the receiver

// requests.push(reqFriend);
await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), {
"uid": get(UserInfoStore).uid,
"coins": get(UserInfoStore).coins,
"rooms": get(UserInfoStore).rooms,
"decorations": get(UserInfoStore).decorations,
"lastLogin": get(UserInfoStore).lastLogin,
// "friends": get(UserInfoStore).friends,
// "requests": get(UserInfoStore).requests,
// "email": get(UserInfoStore).email
});

}
catch (e){
console.log(e);
}
}
export {
loginWithGoogle,
logoutFromGoogle,
addActivity,
getActivities,
buyRoom
buyRoom,
buyDecoration,
addLastLogin
}
13 changes: 11 additions & 2 deletions src/UserInfoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ const UserInfoStore = writable<{
uid: string,
coins: number,
rooms: [string],
decorations: [string]
decorations: [string],
lastLogin: number,
// friends: [string],
// requests: [string],
// email: string
}>({
uid: "",
coins: 0,
rooms: [""],
decorations: [""]
decorations: [""],
lastLogin: -1
// Date.now()
// friends: [""],
// requests: [""],
// email: ""
});

export default {
Expand Down
Loading