-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow.js
69 lines (54 loc) · 2.18 KB
/
follow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Follow products
var url = window.location.pathname;
const itemSlug = url.substring(url.lastIndexOf('/') + 1);
MemberStack.onReady.then(async function (member) {
if (member.loggedIn) {
const metadata = await member.getMetaData();
metadata.followList = metadata.followList || [];
const followNum = metadata.followList.length || 0;
$('.cc-follow-count').text(followNum);
// show/hide watchlist buttons
if (metadata.followList.indexOf(itemSlug) === -1) {
$('.cc-follow-product.cc-checked').hide();
console.log("not following");
}
else {
console.log("following");
$('.cc-follow-product.cc-unchecked').hide();
}
$('.cc-follow-product.cc-unchecked').click(function () {
if (metadata.followList.indexOf(itemSlug) === -1) {
metadata.followList.push(itemSlug);
const followNum = metadata.followList.length || 0;
metadata.followItemsNum = followNum;
member.updateMetaData(metadata);
$('.cc-follow-count').text(followNum);
$('.cc-follow-product.cc-checked').show();
$('.cc-follow-product.cc-unchecked').hide();
}
});
}
});
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.tools = metadata.tools || [];
// Defines the webflow video ID to a const of itemID (Pull this from the CMS)
const itemID = "{{wf {"path":"text-item-id","type":"PlainText"\} }}"
// If they have the item ID in their profile, hide the form, show the 'completed button'
if (metadata.tools.includes(itemID)) {
document.getElementById('add-tool').style.display = 'none';
document.getElementById('tool-added').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.
$('#add-tool').click(function () {
if (metadata.tools.indexOf(itemID) === -1) {
metadata.tools.push(itemID);
member.updateMetaData(metadata);
}
});
}
});