{"version":3,"file":"FollowButton.js","sources":["FollowButton.js"],"sourcesContent":["define(\"Modules/FollowButton\", [`Module`, `module`], function (Super, Self) {\n\treturn Super.inherit({\n\t\tnamespace: Self.id,\n\t\trequires: [`User`, `Events`],\n\t\tdefaults: {\n\t\t\teventId: null,\n\t\t},\n\t\tasync constructor(setup) {\n\t\t\tconst { Events, User, data } = this;\n\t\t\tconst { eventId } = setup;\n\t\t\tconst event = await Events.get({ by: `id`, id: eventId });\n\t\t\tconst following = false;\n\n\t\t\tthis.assign(data, { event, following });\n\t\t\tthis.render();\n\n\t\t\treturn User.get({\n\t\t\t\tforce: false,\n\t\t\t\tsubscribe: true,\n\t\t\t\tthen: (user) => {\n\t\t\t\t\tconst { followedEvents } = user;\n\t\t\t\t\tconst isFollowing = this.isArray(followedEvents) && followedEvents.includes(eventId);\n\n\t\t\t\t\tif (isFollowing) {\n\t\t\t\t\t\tthis.follow();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.unfollow();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tfail: this.unfollow,\n\t\t\t});\n\t\t},\n\n\t\tapi: {\n\t\t\tfollow: {\n\t\t\t\tvalue() {\n\t\t\t\t\tconst { data } = this;\n\t\t\t\t\tconst element = this.get(`.button`);\n\n\t\t\t\t\tthis.addClass(`following`); // add .following to the container\n\t\t\t\t\telement.setAttribute(`theme`, `GRAY`);\n\t\t\t\t\tdata.following = true;\n\t\t\t\t},\n\t\t\t},\n\t\t\tunfollow: {\n\t\t\t\tvalue() {\n\t\t\t\t\tconst { data } = this;\n\t\t\t\t\tconst element = this.get(`.button`);\n\n\t\t\t\t\tthis.removeClass(`following`); // remove .following to the container\n\t\t\t\t\telement.setAttribute(`theme`, `GREEN`);\n\t\t\t\t\tdata.following = false;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\n\t\tlisteners: [\n\t\t\t{\n\t\t\t\tevent: `click`,\n\t\t\t\tfilter: `[action=\"follow\"]`,\n\t\t\t\thandler(evt) {\n\t\t\t\t\tconst { User, data } = this;\n\t\t\t\t\tconst { event, following } = data;\n\t\t\t\t\tconst { id: eventId } = event;\n\n\t\t\t\t\tif (following) {\n\t\t\t\t\t\treturn User.unfollowEvent({ eventId });\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn User.followEvent({ eventId });\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n});\n\ndefine(\"Modules/FollowButton.templates\",[\"handlebars\"], function(Handlebars) {\n\nthis[\"Templates\"] = this[\"Templates\"] || {};\n\nthis[\"Templates\"][\"Modules/FollowButton/main\"] = Handlebars.template({\"1\":function(container,depth0,helpers,partials,data) {\n var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {\n if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {\n return parent[propertyName];\n }\n return undefined\n };\n\n return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? lookupProperty(depth0,\"event\") : depth0)) != null ? lookupProperty(stack1,\"followLabel\") : stack1), depth0));\n},\"3\":function(container,depth0,helpers,partials,data) {\n return \"Follow event\";\n},\"5\":function(container,depth0,helpers,partials,data) {\n var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {\n if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {\n return parent[propertyName];\n }\n return undefined\n };\n\n return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? lookupProperty(depth0,\"event\") : depth0)) != null ? lookupProperty(stack1,\"unfollowLabel\") : stack1), depth0));\n},\"7\":function(container,depth0,helpers,partials,data) {\n return \"Unfollow event\";\n},\"compiler\":[8,\">= 4.3.0\"],\"main\":function(container,depth0,helpers,partials,data) {\n var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty = container.lookupProperty || function(parent, propertyName) {\n if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {\n return parent[propertyName];\n }\n return undefined\n };\n\n return \"

\"\n + ((stack1 = lookupProperty(helpers,\"if\").call(alias1,((stack1 = (depth0 != null ? lookupProperty(depth0,\"event\") : depth0)) != null ? lookupProperty(stack1,\"followLabel\") : stack1),{\"name\":\"if\",\"hash\":{},\"fn\":container.program(1, data, 0),\"inverse\":container.program(3, data, 0),\"data\":data,\"loc\":{\"start\":{\"line\":1,\"column\":75},\"end\":{\"line\":1,\"column\":148}}})) != null ? stack1 : \"\")\n + \"

\"\n + ((stack1 = lookupProperty(helpers,\"if\").call(alias1,((stack1 = (depth0 != null ? lookupProperty(depth0,\"event\") : depth0)) != null ? lookupProperty(stack1,\"unfollowLabel\") : stack1),{\"name\":\"if\",\"hash\":{},\"fn\":container.program(5, data, 0),\"inverse\":container.program(7, data, 0),\"data\":data,\"loc\":{\"start\":{\"line\":1,\"column\":156},\"end\":{\"line\":1,\"column\":235}}})) != null ? stack1 : \"\")\n + \"

\"\n + container.escapeExpression(lookupProperty(helpers,\"getIcon\").call(alias1,\"plus\",{\"name\":\"getIcon\",\"hash\":{},\"data\":data,\"loc\":{\"start\":{\"line\":1,\"column\":240},\"end\":{\"line\":1,\"column\":258}}}))\n + \"
\";\n},\"useData\":true});\n\nreturn this[\"Templates\"];\n\n});\n//# sourceMappingURL=FollowButton.js.map"],"names":["define","Super","Self","inherit","namespace","id","requires","defaults","eventId","constructor","setup","Events","User","data","this","event","await","get","by","following","assign","render","force","subscribe","then","followedEvents","user","isFollowing","isArray","includes","follow","unfollow","fail","api","value","element","addClass","setAttribute","removeClass","listeners","filter","handler","evt","unfollowEvent","followEvent","Handlebars","template","1","container","depth0","helpers","partials","lookupProperty","parent","propertyName","Object","prototype","hasOwnProperty","call","escapeExpression","lambda","stack1","3","5","7","compiler","main","alias1","nullContext","name","hash","fn","program","inverse","loc","start","line","column","end","useData"],"mappings":"AAAAA,OAAO,uBAAwB,CAAC,SAAU,UAAW,SAAUC,EAAOC,GACrE,OAAOD,EAAME,QAAQ,CACpBC,UAAWF,EAAKG,GAChBC,SAAU,CAAC,OAAQ,UACnBC,SAAU,CACTC,QAAS,IACV,EACAC,kB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