{ "version": 3, "sources": ["../../../../../../owl-nest/ulule/features/project/src/public/views/detail/tabs/news/NewsPermalink.tsx"], "sourcesContent": ["import { Link as RouterLink, useLocation } from 'react-router-dom'\nimport * as React from 'react'\nimport * as Redux from 'react-redux'\nimport styled from 'styled-components'\n\nimport { QueryStatus, useQuery } from '@owl-nest/hooks'\nimport { Either } from '@owl-nest/monad'\nimport * as ds from '@ulule/owl-kit-components/next'\nimport { t } from '@owl-nest/localize'\nimport * as api from '@owl-nest/api-client/latest'\nimport { useAuth } from '@owl-nest/redux-wrapper/hooks'\n\nimport { Project } from '../../../../models/project'\nimport { PATHS } from '../../../../paths'\nimport { RootState } from '../../../../../reducers'\nimport { State as CommentState } from '../../../../../reducers/comments'\nimport * as commentAction from '../../../../../actions/comments'\nimport * as Styles from '../../style'\nimport { Comments } from '../../components/Comments'\nimport { News } from './News'\nimport { useNavigation } from '../../../../hooks/useNavigation'\nimport { useDisplayMode } from '../../../../hooks/useDisplayMode'\n\ntype NewsPermalinkProps = {\n news: api.News\n id: number\n}\n\nexport function NewsPermalink({ news, id }: NewsPermalinkProps): React.ReactElement {\n const project = Redux.useSelector((state) => state.application.project.data)\n const auth = useAuth()\n const navigation = useNavigation()\n const location = useLocation()\n const displayMode = useDisplayMode(project)\n const isPreview = displayMode === 'preview'\n\n const children = Redux.useSelector(\n (state) => state.application.comments.list.root,\n )\n const dispatch = Redux.useDispatch()\n\n const isLoggedIn = auth.type === 'loggedin'\n const [query, response] = useQuery(async () => {\n if (news?.id !== id || news === undefined) {\n const result = await api.api.get.news({\n urlParams: { newsId: String(id) },\n withToken: isLoggedIn,\n })\n return result.next((success) => success.body)\n }\n\n return Either.right(news)\n })\n\n React.useEffect(() => {\n if (response.status === QueryStatus.SUCCESS) {\n dispatch(\n commentAction.loadRoot(\n { type: 'news', news: news || response.data },\n { pagination: `?limit=${20}&since=${Math.floor(Date.now() / 1000)}`, forceClean: true },\n ),\n )\n }\n }, [response.status])\n\n React.useEffect(() => {\n if (news?.id !== id) {\n query()\n }\n }, [id])\n\n if (response.status === QueryStatus.PRISTINE) {\n query()\n }\n\n if (response.status !== QueryStatus.SUCCESS) {\n return (\n \n \n \n \n \n \n \n )\n }\n\n news = response.data || news\n\n const isUserStaff = auth.type === 'loggedin' && auth.user.is_staff\n const isUserAllowed = Boolean(news.permissions.self?.includes('read'))\n const projectTeamRoles = [api.UserRole.Owner, api.UserRole.Editor, api.UserRole.Moderator]\n const isProjectTeam = project.user_role && projectTeamRoles.includes(project.user_role)\n const isNewsMasked = !isUserAllowed\n const isWaiting = news.status === api.NewsStatus.WAITING\n\n let hideComments = false\n if (isNewsMasked || isWaiting) {\n // Comments are hidden for masked news and draft ones\n hideComments = true\n } else if (project.comments_enabled === api.ProjectCommentsPermission.NOONE && !isProjectTeam && !isUserStaff) {\n // Also, only staff and project team can access comments when they are disabled\n hideComments = true\n }\n\n return (\n \n \n \n \n \n \n {t('See all posts')}\n \n\n \n\n {!hideComments && (\n dispatch(commentAction.loadRoot({ type: 'news', news }, { pagination: next }))}\n onRootSubmit={async (values) => {\n await dispatch(commentAction.createRoot({ type: 'news', news }, values.comment))\n }}\n />\n )}\n \n \n \n )\n}\n\nconst BackToNewsStyled = styled(ds.Link).attrs((props) => ({ ...props, kind: 'secondary' }))`\n display: block;\n margin-bottom: 31px;\n\n ${ds.glyphs.stroke.ArrowLeft} {\n margin-right: 8px;\n }\n`\n\nconst Anchor = styled.div<{ isPreview: boolean }>`\n position: absolute;\n top: ${({ isPreview }) => (isPreview ? '-108px' : '-60px')};\n`\n"], "mappings": "+uBAAAA,IAAAC,IACA,IAAAC,EAAuB,QA2BhB,SAASC,GAAc,CAAE,KAAAC,EAAM,GAAAC,CAAG,EAA+D,CA5BxG,IAAAC,EA6BE,IAAMC,EAAgBC,EAAiCC,GAAUA,EAAM,YAAY,QAAQ,IAAI,EACzFC,EAAOC,EAAQ,EACfC,EAAaC,EAAc,EAC3BC,EAAWC,EAAY,EAEvBC,EADcC,EAAeV,CAAO,I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AAiB,CAACH,KAEhGM,EAAe,IAIf,gBAAQV,EAAP,KACC,gBAACW,GAAA,CAAO,GAAG,SAAS,UAAWxB,EAAW,EAC1C,gBAAQc,EAAP,KACC,gBAAQC,EAAP,KACC,gBAACU,GAAA,CAAiB,YAAaC,EAAY,GAAI9B,EAAW,OAAO+B,EAAM,IAAI,GACzE,gBAAIC,EAAO,OAAO,UAAjB,CAA2B,KAAM,GAAI,KACrC,KAAE,eAAe,CACpB,EAEA,gBAACC,EAAA,CAAK,KAAMzC,EAAM,KAAI,GAAC,EAEtB,CAACmC,GACA,gBAACO,EAAA,CACC,UAAWhC,EAAS,OAAS,qBAC7B,SAAUI,EACV,WAAa6B,GAAS5B,EAAuBS,EAAS,CAAE,KAAM,OAAQ,KAAAxB,CAAK,EAAG,CAAE,WAAY2C,CAAK,CAAC,CAAC,EACnG,aAAc,MAAOC,GAAW,CAC9B,MAAM7B,EAAuB8B,EAAW,CAAE,KAAM,OAAQ,KAAA7C,CAAK,EAAG4C,EAAO,OAAO,CAAC,CACjF,EACF,CAEJ,CACF,CACF,CAEJ,CAnIA,IAAA1C,EAqIMmC,GAAmBS,EAAUR,CAAI,EAAE,MAAOS,GAAWC,EAAAC,EAAA,GAAKF,GAAL,CAAY,KAAM,WAAY,EAAE,EAAlE7C,MAAmEgD,EAAA,qDAI9D,uCAAvBV,EAAO,OAAO,WAzIrBW,EA8IMf,GAASU,EAAO,IAAPK,MAAkCD,EAAA,oCAEW,SAAnD,CAAC,CAAE,UAAAtC,CAAU,IAAOA,EAAY,SAAW", "names": ["init_define_process_env", "init_sentry_release_injection_stub", "React", "NewsPermalink", "news", "id", "_a", "project", "useSelector", "state", "auth", "useAuth", "navigation", "useNavigation", "location", "useLocation", "isPreview", "useDisplayMode", "children", "dispatch", "useDispatch", "isLoggedIn", "query", "response", "useQuery", "api", "success", "Either", "loadRoot", "Main", "Wrapper", "Content", "Spinner", "isUserStaff", "isUserAllowed", "projectTeamRoles", "isProjectTeam", "isNewsMasked", "isWaiting", "hideComments", "Anchor", "BackToNewsStyled", "Link", "PATHS", "glyphs_exports", "News", "Comments", "next", "values", "createRoot", "src_default", "props", "__spreadProps", "__spreadValues", "__template", "_b"] }