-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #974 Extra infromation on Profile #1031
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca879d1
display user stat box and user location on profile
BenGamma e59c90a
Merge branch 'master' into feat/974-extra-infos-profile
alromh87 40b7deb
Fix #974 Extra infromation on Profile
alromh87 87e9ac9
Merge branch 'master' into feat/974-extra-infos-profile
alromh87 8b6e0c7
Added missing text for User Stats (How-to: , Events:)
alromh87 03b17a9
Profile extra info in correct order and in single line
alromh87 4152e7c
Right color for pin link in profile extras
alromh87 3a85e05
User _stats renamed to stats for #974
alromh87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as functions from 'firebase-functions' | ||
import { db } from '../Firebase/firestoreDB' | ||
|
||
|
||
export const countHowTos = functions.firestore | ||
.document('v3_howtos/{id}') | ||
.onWrite(async (change, context) => { | ||
|
||
updateStats(change, 'v3_howtos', 'howToCount') | ||
|
||
}) | ||
|
||
export const countEvents = functions.firestore | ||
.document('v3_events/{id}') | ||
.onWrite(async (change, context) => { | ||
|
||
updateStats(change, 'v3_events', 'eventCount') | ||
|
||
}) | ||
|
||
function updateStats(change, collection, target){ | ||
|
||
const info = change.after.exists ? change.after.data() : null | ||
const prevInfo = change.before.exists ? change.before.data() : null | ||
const userStatsRef = db.collection('v3_users/'); | ||
|
||
let delta = 0 | ||
|
||
if (info !== null && info.moderation === 'accepted' && prevInfo !== null && prevInfo.Moderation !== 'accepted') { // Increment if now accepted and previously different | ||
delta = 1 | ||
} else if (prevInfo !== null && prevInfo.moderation === 'accepted' && (info === null || info.moderation !== 'accepted')) { // Decrement if previously accepted and now erased or moderation changed | ||
delta = -1 | ||
} else { | ||
return null | ||
} | ||
|
||
console.log('Update ', collection, ' delta: ', delta ) | ||
|
||
return userStatsRef.doc(info._createdBy).update({'_stats':{ | ||
[target]: admin.firestore.FieldValue.increment(delta) | ||
}}).catch(e => { | ||
console.log(e); | ||
// In case stats for user are inexistent we compute from all his records, Only triggers if no user exist (new Collection) | ||
// computeUserStats(info._createdBy) | ||
}) | ||
} | ||
|
||
// Compute one user stats | ||
function computeUserStats(owner){ | ||
|
||
const userStatsRef = db.collection('v3_users/') | ||
|
||
db.collection('v3_howtos').where("_createdBy", "==", owner).where("moderation", "==", "accepted") | ||
.get() | ||
.then(querySnapshot => { | ||
let count = 0; | ||
querySnapshot.forEach(doc => { | ||
count++; | ||
}); | ||
console.log('Accepted howtos for', owner ,',count: ', count); | ||
userStatsRef.doc(owner).set({'_stats':{ | ||
howToCount: count | ||
}}, {merge: true}); | ||
return null | ||
}).catch(() => null); | ||
|
||
db.collection('v3_events').where("_createdBy", "==", owner).where("moderation", "==", "accepted") | ||
.get() | ||
.then(querySnapshot => { | ||
let count = 0; | ||
querySnapshot.forEach(doc => { | ||
count++; | ||
}); | ||
console.log('Accepted events for', owner ,',count: ', count); | ||
userStatsRef.doc(owner).set({'_stats':{ | ||
eventCount: count | ||
}}, {merge: true}); | ||
return null | ||
}).catch(() => null); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case it will be better to extend the props from rebass BoxProps directly, but I don't think you need to add it here, and I don't see it used anywhere else anyway ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was needed to be able to change the margin of the internal box, which had it fixed to 4, now it will default to 4(avoid braking other displays), but can be overwiten when usng component, used to make howto event display in one line
03b17a9
Maybe your right, but i dont know how to do that 😓