diff --git a/sites/org/components/layouts/post.mjs b/sites/org/components/layouts/post.mjs index a16afde7dba..b60e496f3aa 100644 --- a/sites/org/components/layouts/post.mjs +++ b/sites/org/components/layouts/post.mjs @@ -1,3 +1,7 @@ +import { useContext, useState } from 'react' +import { ModalContext } from 'shared/context/modal-context.mjs' +import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs' +import { ModalWrapper } from 'shared/components/wrappers/modal.mjs' import { cloudflareImageUrl, nsMerge } from 'shared/utils.mjs' import { makers } from 'site/prebuild/makers.mjs' // Components @@ -6,6 +10,7 @@ import { Lightbox } from 'shared/components/lightbox.mjs' import { ImageWrapper } from 'shared/components/wrappers/img.mjs' import { TimeAgo, ns as timeagoNs } from 'shared/components/timeago/index.mjs' import { useTranslation } from 'next-i18next' +import { Link } from 'shared/components/link.mjs' import { BaseLayout, BaseLayoutLeft, @@ -23,8 +28,12 @@ import { Toc, ns as tocNs } from 'shared/components/mdx/toc.mjs' import { PrevNext } from 'shared/components/prev-next.mjs' import { Tag } from 'shared/components/tag.mjs' import { UserProfile } from 'shared/components/user-profile.mjs' +import { useAccount } from 'shared/hooks/use-account.mjs' +import { useBackend } from 'shared/hooks/use-backend.mjs' +import { MarkdownInput } from 'shared/components/inputs.mjs' +import { userCard } from 'shared/components/support/support.mjs' -export const ns = nsMerge(navNs, tocNs, timeagoNs, 'docs') +export const ns = nsMerge(navNs, tocNs, timeagoNs, 'docs', 'account') const PostMeta = ({ frontmatter, t }) => (
@@ -70,41 +79,187 @@ export const PostImage = ({ imgId, frontmatter }) => ( ) +const createIssue = async ({ account, setLoadingStatus, title, body, backend, setModal }) => { + setLoadingStatus([true, 'account:oneMomentPlease']) + const issueData = { + title, + body: account ? `${body}\n\n${userCard(account.id || false)}` : body, + labels: ['%3A%2B1%3A+good+first+issue'], + } + const result = await backend.createIssue(issueData) + if (result.success) { + setLoadingStatus([true, 'account:nailedIt', true, true]) + setModal( + +
+

Issue created

+

Thank you for helping out.

+

+ We created a new issue for this. +
+ If you would like to help out even more, the issue describes what file to change and + what change needs to be made. +

+

+ You can do this via the GitHub website, so it is a great way to make a first + contribution if you are new to open source. +

+
+
+ ) + } else setLoadingStatus([true, 'backendError', true, false]) +} + export const PostContent = ({ mdx, dir }) => (
) -const ClaimThisPost = ({ t, type }) => ( -
-

Claim this post

-

- This post has not (yet) been associated with a FreeSewing account. Please help us assign - proper credit: +const ClaimAuthor = ({ t, type }) => ( +

+

{t(`docs:i${type === 'blog' ? 'Wrote' : 'Made'}This`)}

+

Great, but it looks like you are not currently logged in.

+

Please log in and then claim this post so we know what account to associate it with.

+

+ + Sign In +

-
- - -
) -const Maker = ({ id, type, t }) => +const issueData = ({ type, dir, account, body = false }) => ({ + title: body + ? `An author suggestion was submitted for the ${type} post ${dir}` + : `The ${type} post ${dir} was claimed as their own by user ${account.id}`, + body: `This issue is about who should get credit for [this ${type} post](https://freesewing.org/${type}/${dir}). + +According to [user ${account.username}](https://freesewing.org.users/user?id=${account.id}) with ID ${account.id}, +${body ? 'who wrote:\n\n---\n\n' + body + '\n\n---\n\n' : 'who claimed it as their own'}. + +To reflect this on the site, update [this markdown file](https://github.com/freesewing/freesewing/blob/develop/markdown/org/${type}/${dir}/en.md) so that the frontmatter includes this: + +\`\`\`md +author: ${body ? 'the FreeSewing user ID' : account.id} +\`\`\` + +Anyone can do this, so if you're looking to contribute, this is a great way to get started.`, +}) + +const SuggestAuthor = ({ t, type, setLoadingStatus, backend, dir, setModal }) => { + const { account } = useAccount() + const [body, setBody] = useState('') + + return ( + <> +

{t(`docs:iKnowWho${type === 'blog' ? 'Wrote' : 'Made'}This`)}

+

Awesome. Please let us know below who it was by providing either:

+ + val.length > 10} + /> +

When you are done, click the button below to submit.

+

+ +

+ + ) +} + +const ClaimThisPost = ({ t, type, dir }) => { + const { setModal } = useContext(ModalContext) + const { account } = useAccount() + const backend = useBackend() + const { setLoadingStatus } = useContext(LoadingStatusContext) + + return ( +
+

Claim this post

+

+ This post has not (yet) been associated with a FreeSewing account. Please help us assign + proper credit: +

+
+ + +
+
+ ) +} + +const Maker = ({ id, type, t, dir }) => makers[id] ? (
-
+
{t(`docs:${type === 'blog' ? 'writtenBy' : 'madeBy'}`)}
) : ( - + ) /** layout for a page that displays a blog, showcase or newsletter */ @@ -138,6 +293,7 @@ export const PostLayout = ({ mdx, frontmatter, type, dir }) => { id={type === 'blog' ? frontmatter.author : frontmatter.maker} type={type} t={t} + dir={dir} /> diff --git a/sites/shared/components/support/support.mjs b/sites/shared/components/support/support.mjs index 3fec88ddeb3..8cde2650ba9 100644 --- a/sites/shared/components/support/support.mjs +++ b/sites/shared/components/support/support.mjs @@ -47,7 +47,7 @@ const types = [ 'other', ] -const userCard = (id) => +export const userCard = (id) => `[![User ${id}](${config.backend}/users/${id}/card)](https://next.freesewing.org/users/${id})` const templates = { diff --git a/sites/shared/i18n/docs/en.yaml b/sites/shared/i18n/docs/en.yaml index 7a5005a4992..19722875424 100644 --- a/sites/shared/i18n/docs/en.yaml +++ b/sites/shared/i18n/docs/en.yaml @@ -23,8 +23,8 @@ credits: Credits contentsBy: Contents by translators: Translators title: Title -xMadeThis: "{x} made this" -xWroteThis: "{x} wrote this" +writtenBy: Written by +madeBy: Made by by: By claimThisPost: Claim this post iKnowWhoMadeThis: I know who made this