From 2516fd36e0bbbfedc4de7e153b58008a058ff62d Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 19 Apr 2023 16:28:15 -0400 Subject: [PATCH 1/6] Update 'Create Group' modal title dynamically --- .../manage-group-modal/create-group-modal.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx index bbeb2d43e..068cf82ec 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx @@ -33,7 +33,9 @@ const CreateGroupModal: React.FC = ({ onClose }) => { const debounce = useDebounce; const [group, setGroup] = useState(null); - const [params, setParams] = useState({}); + const [params, setParams] = useState({ + group_visibility: 'everyone', + }); const [currentStep, setCurrentStep] = useState(Steps.ONE); const { createGroup, isSubmitting } = useCreateGroup(); @@ -96,9 +98,22 @@ const CreateGroupModal: React.FC = ({ onClose }) => { } }; + const renderModalTitle = () => { + switch (currentStep) { + case Steps.ONE: + return ; + default: + if (params.group_visibility === 'everyone') { + return ; + } else { + return ; + } + } + }; + return ( } + title={renderModalTitle()} confirmationAction={handleNextStep} confirmationText={confirmationText} confirmationDisabled={isSubmitting || (currentStep === Steps.TWO && !isValid)} From e43a9164b7b96f7d460d28437e46e32e0df2b180 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 19 Apr 2023 16:44:00 -0400 Subject: [PATCH 2/6] Update modal title in Group creation --- .../modals/manage-group-modal/create-group-modal.tsx | 2 +- app/soapbox/locales/en.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx index 068cf82ec..9f5d143a7 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx @@ -14,7 +14,7 @@ import PrivacyStep from './steps/privacy-step'; const messages = defineMessages({ next: { id: 'manage_group.next', defaultMessage: 'Next' }, - create: { id: 'manage_group.create', defaultMessage: 'Create' }, + create: { id: 'manage_group.create', defaultMessage: 'Create Group' }, done: { id: 'manage_group.done', defaultMessage: 'Done' }, }); diff --git a/app/soapbox/locales/en.json b/app/soapbox/locales/en.json index f7f1f20e1..8e5c8e306 100644 --- a/app/soapbox/locales/en.json +++ b/app/soapbox/locales/en.json @@ -965,7 +965,7 @@ "manage_group.confirmation.info_3": "Share your new group with friends, family and followers to grow its membership.", "manage_group.confirmation.share": "Share this group", "manage_group.confirmation.title": "You’re all set!", - "manage_group.create": "Create", + "manage_group.create": "Create Group", "manage_group.delete_group": "Delete group", "manage_group.done": "Done", "manage_group.edit_group": "Edit group", @@ -1055,6 +1055,8 @@ "navigation_bar.compose_reply": "Reply to post", "navigation_bar.create_event": "Create new event", "navigation_bar.create_group": "Create Group", + "navigation_bar.create_group.private": "Create Private Group", + "navigation_bar.create_group.public": "Create Public Group", "navigation_bar.domain_blocks": "Domain blocks", "navigation_bar.edit_group": "Edit Group", "navigation_bar.favourites": "Likes", From 68be77fa542f3eabaa57ab6ff5da9b744ad76f20 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 19 Apr 2023 16:44:22 -0400 Subject: [PATCH 3/6] Use 'copy' function for copying group uri --- .../steps/confirmation-step.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx index 7db6d9c20..af1a5c363 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { Avatar, Divider, HStack, Stack, Text, Button } from 'soapbox/components/ui'; +import copy from 'soapbox/utils/copy'; import type { Group } from 'soapbox/schemas'; @@ -10,11 +11,7 @@ interface IConfirmationStep { } const ConfirmationStep: React.FC = ({ group }) => { - const handleCopyLink = () => { - if (navigator.clipboard) { - navigator.clipboard.writeText(group.uri); - } - }; + const handleCopyLink = () => copy(group.uri); const handleShare = () => { navigator.share({ @@ -90,9 +87,11 @@ const ConfirmationStep: React.FC = ({ group }) => { )} - + {group.uri && ( + + )} ); From 2813b02329aec05851cdfb6340018d402a91168d Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 19 Apr 2023 16:45:26 -0400 Subject: [PATCH 4/6] Coerce group 'id' into String --- app/soapbox/schemas/group.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/schemas/group.ts b/app/soapbox/schemas/group.ts index 827531ee7..746ae9d33 100644 --- a/app/soapbox/schemas/group.ts +++ b/app/soapbox/schemas/group.ts @@ -22,7 +22,7 @@ const groupSchema = z.object({ group_visibility: z.string().catch(''), // TruthSocial header: z.string().catch(headerMissing), header_static: z.string().catch(''), - id: z.string(), + id: z.coerce.string(), locked: z.boolean().catch(false), membership_required: z.boolean().catch(false), members_count: z.number().catch(0), From c87589be4ecd17db2abdf7fc854b477772a98645 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 19 Apr 2023 16:51:07 -0400 Subject: [PATCH 5/6] Build group URI and handle successful copying --- .../steps/confirmation-step.tsx | 23 +++++++++++++------ app/soapbox/utils/copy.ts | 10 +++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx index af1a5c363..f0be4f73b 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/confirmation-step.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import { FormattedMessage } from 'react-intl'; +import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { Avatar, Divider, HStack, Stack, Text, Button } from 'soapbox/components/ui'; +import toast from 'soapbox/toast'; import copy from 'soapbox/utils/copy'; import type { Group } from 'soapbox/schemas'; @@ -10,8 +11,18 @@ interface IConfirmationStep { group: Group } +const messages = defineMessages({ + copied: { id: 'copy.success', defaultMessage: 'Copied to clipboard!' }, +}); + const ConfirmationStep: React.FC = ({ group }) => { - const handleCopyLink = () => copy(group.uri); + const intl = useIntl(); + + const handleCopyLink = () => { + copy(`${window.location.origin}/group/${group.slug}`, () => { + toast.success(intl.formatMessage(messages.copied)); + }); + }; const handleShare = () => { navigator.share({ @@ -87,11 +98,9 @@ const ConfirmationStep: React.FC = ({ group }) => { )} - {group.uri && ( - - )} + ); diff --git a/app/soapbox/utils/copy.ts b/app/soapbox/utils/copy.ts index 4eea324f5..57aa2de8c 100644 --- a/app/soapbox/utils/copy.ts +++ b/app/soapbox/utils/copy.ts @@ -1,6 +1,10 @@ -const copy = (text: string) => { +const copy = (text: string, onSuccess?: () => void) => { if (navigator.clipboard) { navigator.clipboard.writeText(text); + + if (onSuccess) { + onSuccess(); + } } else { const textarea = document.createElement('textarea'); @@ -16,6 +20,10 @@ const copy = (text: string) => { // Do nothing } finally { document.body.removeChild(textarea); + + if (onSuccess) { + onSuccess(); + } } } }; From 67a5240e43e4f7c8565b89362aff14b36e07fc38 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Thu, 20 Apr 2023 09:51:40 -0400 Subject: [PATCH 6/6] Add locale --- app/soapbox/locales/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/app/soapbox/locales/en.json b/app/soapbox/locales/en.json index 8e5c8e306..8a8e23db7 100644 --- a/app/soapbox/locales/en.json +++ b/app/soapbox/locales/en.json @@ -528,6 +528,7 @@ "confirmations.scheduled_status_delete.heading": "Cancel scheduled post", "confirmations.scheduled_status_delete.message": "Are you sure you want to cancel this scheduled post?", "confirmations.unfollow.confirm": "Unfollow", + "copy.success": "Copied to clipboard!", "crypto_donate.explanation_box.message": "{siteTitle} accepts cryptocurrency donations. You may send a donation to any of the addresses below. Thank you for your support!", "crypto_donate.explanation_box.title": "Sending cryptocurrency donations", "crypto_donate_panel.actions.view": "Click to see {count, plural, one {# wallet} other {# wallets}}",