{"version":3,"sources":["webpack:///./app/javascript/utilities/http/request.js","webpack:///./app/javascript/CommentSubscription/CommentSubscription.jsx","webpack:///./app/javascript/CommentSubscription/commentSubscriptionUtilities.jsx"],"names":["request","url","options","headers","body","method","csrfToken","getCsrfToken","restOfOptions","jsonifiedBody","JSON","stringify","fetchOptions","Accept","credentials","fetch","COMMENT_SUBSCRIPTION_TYPE","Object","freeze","ALL","TOP","AUTHOR","NOT_SUBSCRIBED","CommentSubscription","props","subscriptionType","commentSubscriptionClick","event","setState","target","value","subscribed","length","initialState","showOptions","state","this","onSubscribe","onUnsubscribe","positionType","isLoggedIn","className","ref","element","buttonGroupElement","variant","onClick","_event","showLoginModal","id","icon","xmlns","width","height","role","d","contentType","triggerButtonId","dropdownContentId","dropdownContentCloseButtonId","dropdownElement","onOpen","onClose","name","checked","htmlFor","Component","displayName","propTypes","PropTypes","oneOf","isRequired","func","entries","map","bool","getCommentSubscriptionStatus","articleId","response","json","error","Error","setCommentSubscriptionStatus","message","config","replace"],"mappings":"khDAsBO,SAAeA,EAAtB,kC,yBAAO,UAAuBC,GAAoB,IAAfC,EAAc,uDAAJ,GAEzCC,EAMED,EANFC,QACAC,EAKEF,EALFE,KAFF,EAOIF,EAJFG,cAHF,MAGW,MAHX,IAOIH,EAHFI,iBAJF,YAIoBC,eAJpB,EAMKC,EANL,EAOIN,EAPJ,GAWMO,EAAgB,CACpBL,KAAMA,GAAwB,kBAATA,EAAoBM,KAAKC,UAAUP,GAAQA,GAG5DQ,EAAY,KAChBP,SACAF,QAAQ,EAAD,CACLU,OAAQ,mBACR,eAAgBP,EAChB,eAAgB,oBACbH,GAELW,YAAa,eACVL,GACAD,GAGL,OAAOO,MAAMd,EAAKW,M,+lFCvCb,IAAMI,EAA4BC,OAAOC,OAAO,CACrDC,IAAK,eACLC,IAAK,qBACLC,OAAQ,uBACRC,eAAgB,mBAGLC,EAAb,a,mOAAA,U,MAAA,OACE,WAAYC,GAAQ,IAAD,G,4FAAA,SACjB,IAA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tB,kC,yBAAO,UAA4CC,GACjD,IACE,IAAMC,QAAiB9E,YAAQ,uCAAD,OACW6E,IAKzC,aAFiCC,EAASC,OAG1C,MAAOC,GACP,OAAO,IAAIC,MAAM,4C,sBAYd,SAAeC,EAAtB,oC,yBAAO,UACLL,EACApD,GAEA,IAAI0D,EAEJ,IACE,IAAML,QAAiB9E,YAAQ,uCAAD,OACW6E,GACvC,CACExE,OAAQ,OACRD,KAAMM,KAAKC,UAAU,CAAEyE,OAAQ3D,MAK7BM,QAAmB+C,EAASC,OAElC,GAA0B,mBAAfhD,EAGT,OAFAoD,EAAU,sCAKZA,EAAU,yDAENpD,IACFoD,EAAO,sCAAkC1D,EAAiB4D,QACxD,KACA,OAGJ,MAAOL,GACPG,EAAU,sCAGZ,OAAOA,M","file":"js/116-1c0e4b56782a8fab051e.chunk.js","sourcesContent":["/**\n * Generic request with all the default headers required by the application.\n *\n * @example\n * import { request } from '@utilities/http';\n *\n * const response = await request('/notification_subscriptions/Article/26')\n *\n * Note:\n * The body option will typically be passed in as a JavaScript object.\n * A check is performed for this and automatically convert it to JSON if necessary.\n *\n * Requests send JSON by default but this can be easily overridden by adding\n * the Accept and Content-Type headers to the request options.\n *\n * The default method is GET.\n *\n * @param {string} url The URL to make the request to.\n * @param {RequestInit} [options={}] The request options.\n *\n * @return {Promise} the response\n */\nexport async function request(url, options = {}) {\n const {\n headers,\n body,\n method = 'GET',\n csrfToken = await getCsrfToken(),\n // These are any other options that might be passed in e.g. keepalive\n ...restOfOptions\n } = options;\n\n // There should never be a scenario where null is passed as the body,\n // but if ever there is, this logic should change.\n const jsonifiedBody = {\n body: body && typeof body !== 'string' ? JSON.stringify(body) : body,\n };\n\n const fetchOptions = {\n method,\n headers: {\n Accept: 'application/json',\n 'X-CSRF-Token': csrfToken,\n 'Content-Type': 'application/json',\n ...headers,\n },\n credentials: 'same-origin',\n ...jsonifiedBody,\n ...restOfOptions,\n };\n\n return fetch(url, fetchOptions);\n}\n","/* global showLoginModal */\n\nimport { h, Component } from 'preact';\nimport PropTypes from 'prop-types';\nimport {\n Button,\n ButtonGroup,\n Dropdown,\n FormField,\n RadioButton,\n} from '@crayons';\n\nexport const COMMENT_SUBSCRIPTION_TYPE = Object.freeze({\n ALL: 'all_comments',\n TOP: 'top_level_comments',\n AUTHOR: 'only_author_comments',\n NOT_SUBSCRIBED: 'not_subscribed',\n});\n\nexport class CommentSubscription extends Component {\n constructor(props) {\n const { subscriptionType } = props;\n super(props);\n\n const subscribed =\n subscriptionType &&\n (subscriptionType.length > 0 && subscriptionType) !==\n COMMENT_SUBSCRIPTION_TYPE.NOT_SUBSCRIBED;\n\n const initialState = {\n subscriptionType: subscribed\n ? subscriptionType\n : COMMENT_SUBSCRIPTION_TYPE.ALL,\n subscribed,\n showOptions: false,\n };\n\n this.state = initialState;\n }\n\n commentSubscriptionClick = (event) => {\n this.setState({\n subscriptionType: event.target.value,\n });\n };\n\n render() {\n const { subscriptionType, subscribed } = this.state;\n const {\n onSubscribe,\n onUnsubscribe,\n positionType = 'relative',\n isLoggedIn,\n } = this.props;\n\n const CogIcon = () => (\n \n Preferences\n \n \n );\n\n return (\n
\n {\n this.buttonGroupElement = element;\n }}\n >\n {\n if (isLoggedIn) {\n if (subscribed) {\n onUnsubscribe(COMMENT_SUBSCRIPTION_TYPE.NOT_SUBSCRIBED);\n this.setState({\n subscriptionType: COMMENT_SUBSCRIPTION_TYPE.ALL,\n });\n } else {\n onSubscribe(subscriptionType);\n }\n\n this.setState({ subscribed: !subscribed });\n } else {\n showLoginModal();\n }\n }}\n >\n {subscribed ? 'Unsubscribe' : 'Subscribe'}\n \n {subscribed ? (\n \n ) : null}\n \n {subscribed && (\n {\n this.dropdownElement = element;\n }}\n onOpen={() => this.setState({ showOptions: true })}\n onClose={() => this.setState({ showOptions: false })}\n >\n
\n \n \n \n \n\n \n \n \n Top-level comments\n

\n You’ll receive notifications only for all new top-level\n comments.\n

\n \n
\n\n \n \n \n Post author comments\n

\n You’ll receive notifications only if post author sends a new\n comment.\n

\n \n
\n
\n\n {\n onSubscribe(this.state.subscriptionType);\n }}\n >\n Done\n \n \n )}\n
\n );\n }\n}\n\nCommentSubscription.displayName = 'CommentSubscription';\n\nCommentSubscription.propTypes = {\n positionType: PropTypes.oneOf(['absolute', 'relative', 'static']).isRequired,\n onSubscribe: PropTypes.func.isRequired,\n onUnsubscribe: PropTypes.func.isRequired,\n subscriptionType: PropTypes.oneOf(\n Object.entries(COMMENT_SUBSCRIPTION_TYPE).map(([, value]) => value),\n ).isRequired,\n isLoggedIn: PropTypes.bool.isRequired,\n};\n","import { request } from '../utilities/http/request';\n\n/**\n * Gets the comment subscription status for a given article.\n *\n * @param {number} articleId\n *\n * @returns {string} The subscription status.\n */\nexport async function getCommentSubscriptionStatus(articleId) {\n try {\n const response = await request(\n `/notification_subscriptions/Article/${articleId}`,\n );\n\n const subscriptionStatus = await response.json();\n\n return subscriptionStatus;\n } catch (error) {\n return new Error('An error occurred, please try again');\n }\n}\n\n/**\n * Set's the subscription status for a given article.\n *\n * @param {number} articleId\n * @param {string} subscriptionType\n *\n * @returns {string} A friendly message in regards to subscription status.\n */\nexport async function setCommentSubscriptionStatus(\n articleId,\n subscriptionType,\n) {\n let message;\n\n try {\n const response = await request(\n `/notification_subscriptions/Article/${articleId}`,\n {\n method: 'POST',\n body: JSON.stringify({ config: subscriptionType }),\n },\n );\n\n // true means you're subscribed, false means unsubscribed\n const subscribed = await response.json();\n\n if (typeof subscribed !== 'boolean') {\n message = 'An error occurred, please try again';\n\n return message;\n }\n\n message = 'You have been unsubscribed from comments for this post';\n\n if (subscribed) {\n message = `You have been subscribed to ${subscriptionType.replace(\n /_/g,\n ' ',\n )}`;\n }\n } catch (error) {\n message = 'An error occurred, please try again';\n }\n\n return message;\n}\n"],"sourceRoot":""}