Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliams1188 committed Aug 6, 2020
1 parent bb10da1 commit 6925d8e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 28 deletions.
4 changes: 2 additions & 2 deletions client/companies.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function followCompany(companyId, reverse) {

async function updateCompany(id, object) {
await USER_COMPANY.doc(`${currentUser.id}-${id}`).set(object, { merge: true })
.then(() => console.log('user_company updated'))
.then(() => console.log(object))
.catch(error => handleError(error))

await USERS.doc(currentUser.id).collection('companies').doc(id).set(object, { merge: true })
.then(() => console.log('user/companies updated'))
.then(() => console.log(object))
.catch(error => handleError(error))


Expand Down
71 changes: 71 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,77 @@
<script src="tutorials.js"></script>
<script src="dashboard.js"></script>

<script>
MemberStack.onReady.then(async function (member) {

// Checks if member is logged in
if (member.loggedIn) {

const metadata = await member.getMetaData();

// If no metadata.video exists, create it in MemberStack.
metadata.videos = metadata.videos || [];

// Defines the webflow video ID to a const of itemID (Pull this from the CMS)
const itemID = "{{wf {&quot;path&quot;:&quot;item-id&quot;,&quot;type&quot;:&quot;PlainText&quot;\} }}"

// If they have the item ID in their profile, hide the form, show the 'completed button'
if (metadata.videos.includes(itemID)) {
document.getElementById('mark-as-watched').style.display = 'none';
document.getElementById('video-complete').style.display = 'block';
}

// When the button is clicked, if the itemID doesn't exist on their profile
// add it, then push the metadata to MemberStack.
$('#mark-as-watched').click(function () {

if (metadata.videos.indexOf(itemID) === -1) {

metadata.videos.push(itemID);

member.updateMetaData(metadata);

}
});
}
});
</script>

<script>
MemberStack.onReady.then(async function (member) {

// Checks if member is logged in
if (member.loggedIn) {

const metadata = await member.getMetaData();

// If no metadata.video exists, create it in MemberStack.
metadata.watchlist = metadata.watchlist || [];

// Defines the webflow video ID to a const of itemID (Pull this from the CMS)
const itemID = "{{wf {&quot;path&quot;:&quot;item-id&quot;,&quot;type&quot;:&quot;PlainText&quot;\} }}"

// If they have the item ID in their profile, hide the form, show the 'completed button'
if (metadata.watchlist.includes(itemID)) {
document.getElementById('mark-as-listed').style.display = 'none';
document.getElementById('listed').style.display = 'block';
}

// When the button is clicked, if the itemID doesn't exist on their profile
// add it, then push the metadata to MemberStack.
$('#mark-as-listed').click(function () {

if (metadata.watchlist.indexOf(itemID) === -1) {

metadata.watchlist.push(itemID);

member.updateMetaData(metadata);

}
});
}
});
</script>

</body>

Expand Down
42 changes: 23 additions & 19 deletions client/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@ async function createProject(data) {
let image = $('#image')[0].files[0]
data.slug = slugify(data.name)

if (await slugExists()) return handleError('Project name already exists.')
// if (await slugExists(data.slug)) return handleError('Project name already exists.')

db.collection('projects').doc(data.slug).set({
user: currentUser.id,
ref: db.doc(`memberstack_users/${currentUser.id}`),
...data
})
.then(doc => {
console.log(image)
storage
.ref()
.child(`project_images/${data.slug}`)
.put(image)
handleSuccess('Project added')
$('#wf-form-Submit-Project')[0].reset()
if (await slugExists(data.slug) == false) {
return db.collection('projects').doc(data.slug).set({
user: currentUser.id,
ref: db.doc(`memberstack_users/${currentUser.id}`),
...data
})
.catch(error => handleError(error))
.then(doc => {
console.log(image)
storage
.ref()
.child(`project_images/${data.slug}`)
.put(image)
handleSuccess('Project added')
$('#wf-form-Submit-Project')[0].reset()
})
.catch(error => handleError(error))
} else {
return handleError('Project name already exists.')
}
}

function followProject(projectId, reverse) {
Expand All @@ -49,12 +53,12 @@ function followProject(projectId, reverse) {
}

async function updateProject(id, object) {
await PROJECT.doc(currentUser.id).collection('companies').doc(id).set(object, { merge: true })
.then(() => console.log('user/companies updated'))
await PROJECTS.doc(currentUser.id).collection('companies').doc(id).set(object, { merge: true })
.then(() => console.log(object))
.catch(error => handleError(error))

await USER_PROJECT.doc(`${currentUser.id}-${id}`).set(object, { merge: true })
.then(() => console.log('user_company updated'))
.then(() => console.log(object))
.catch(error => handleError(error))

// object[`users.${currentUser.id}`] = object
Expand All @@ -64,7 +68,7 @@ async function updateProject(id, object) {
}

function slugExists(slug) {
return PROJECT.doc(slug).get()
return PROJECTS.doc(slug).get()
.then(doc => {
if (doc.exists) return true
return false
Expand Down
14 changes: 7 additions & 7 deletions client/tutorials.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const increment = firebase.firestore.FieldValue.increment(1)
const decrement = firebase.firestore.FieldValue.increment(-1)
let increment = firebase.firestore.FieldValue.increment(1)
let decrement = firebase.firestore.FieldValue.increment(-1)

let tutorial = getTutorialFromUrl()

function viewedTutorial(id = 'C36CUuTgkhr1p6P8cQn5') {
TUTORIALS
Expand Down Expand Up @@ -33,9 +35,11 @@ function markTutorialComplete(tutorialId, reverse) {

function updateTutorial(id, object) {
USER_TUTORIAL.doc(`${currentUser.id}-${id}`).set(object, { merge: true })
.then(doc => console.log(object))
.catch(error => handleError(error))

USERS.doc(currentUser.id).collection('tutorials').doc(id).set(object, { merge: true })
USERS.doc(currentUser.id).collection('tutorial').doc(id).set(object, { merge: true })
.then(doc => console.log(object))
.catch(error => handleError(error))
}

Expand All @@ -44,31 +48,27 @@ function updateTutorial(id, object) {

// mark watch later
$('.cc-save-item.cc-unchecked').click(() => {
let tutorial = getTutorialFromUrl()
markTutorialWatchLater(tutorial)
$('.cc-save-item.cc-checked').show()
$('.cc-save-item.cc-unchecked').hide()
})

// unmark watch later
$('.cc-save-item.cc-checked').click(() => {
let tutorial = getTutorialFromUrl()
markTutorialWatchLater(tutorial, true)
$('.cc-save-item.cc-checked').hide()
$('.cc-save-item.cc-unchecked').show()
})

// mark complete
$('.cc-mark-as-complete.cc-unchecked').click(() => {
let tutorial = getTutorialFromUrl()
markTutorialComplete(tutorial)
$('.cc-mark-as-complete.cc-checked').show()
$('.cc-mark-as-complete.cc-unchecked').hide()
})

// unmark complete
$('.cc-mark-as-complete.cc-checked').click(() => {
let tutorial = getTutorialFromUrl()
markTutorialComplete(tutorial, true)
$('.cc-mark-as-complete.cc-checked').hide()
$('.cc-mark-as-complete.cc-unchecked').show()
Expand Down

0 comments on commit 6925d8e

Please sign in to comment.