Skip to content

Commit f09652e

Browse files
authored
Merge pull request #11124 from neinteractiveliterature/nbudin/issue8049
Allow regular users to attach images on their own events
2 parents 20a703d + dcfbf2d commit f09652e

42 files changed

Lines changed: 442 additions & 94 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/graphql/graphql_operations_generated.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

app/javascript/BuiltInFormControls/AddFileModal.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ export default function AddFileModal({ visible, existingFiles, addBlob, fileChos
8181
menu: (provided) => ({ ...provided, zIndex: 25 }),
8282
}}
8383
/>
84-
{data?.currentAbility.can_create_cms_files && (
85-
<div className="card mt-2">
86-
<FileUploadForm onUpload={uploadedFile} />
87-
</div>
88-
)}
84+
<div className="card mt-2">
85+
<FileUploadForm onUpload={uploadedFile} />
86+
</div>
8987
{file && (
9088
<div className="card mt-2">
9189
<div className="card-header">{t('cms.addFileModal.filePreview.title')}</div>

app/javascript/BuiltInFormControls/MarkdownInput.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@neinteractiveliterature/litform';
1010
import { useTranslation } from 'react-i18next';
1111
import { markdown } from '@codemirror/lang-markdown';
12-
import { ComponentProps, useMemo } from 'react';
12+
import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react';
1313
import { Extension } from '@codemirror/state';
1414

1515
import parsePageContent from '../parsePageContent';
@@ -44,6 +44,33 @@ export type ImageAttachmentConfig = {
4444
addBlob: (blob: Blob) => void;
4545
};
4646

47+
export function useImageAttachmentConfig(
48+
initialExistingImages: ActiveStorageAttachment[],
49+
uploadImage: (blob: Blob) => Promise<ActiveStorageAttachment | undefined>,
50+
) {
51+
const uploadImageRef = useRef(uploadImage);
52+
const [newImages, setNewImages] = useState<ActiveStorageAttachment[]>([]);
53+
54+
useEffect(() => {
55+
uploadImageRef.current = uploadImage;
56+
}, [uploadImage]);
57+
58+
const config = useMemo<ImageAttachmentConfig>(
59+
() => ({
60+
addBlob: async (blob) => {
61+
const attachment = await uploadImageRef.current(blob);
62+
if (attachment) {
63+
setNewImages((prevNewImages) => [...prevNewImages, attachment]);
64+
}
65+
},
66+
existingImages: [...initialExistingImages, ...newImages],
67+
}),
68+
[initialExistingImages, newImages],
69+
);
70+
71+
return config;
72+
}
73+
4774
export type MarkdownInputProps = Omit<
4875
ComponentProps<typeof CodeInput>,
4976
'getPreviewContent' | 'editorRef' | 'editButtonText' | 'previewButtonText'

app/javascript/BuiltInFormControls/previewQueries.generated.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export type PreviewLiquidQueryVariables = Types.Exact<{
77
}>;
88

99

10-
export type PreviewLiquidQueryData = { __typename: 'Query', cmsParent: { __typename: 'Convention', id: string, previewLiquid: string } | { __typename: 'RootSite', id: string, previewLiquid: string } };
10+
export type PreviewLiquidQueryData = { __typename: 'Query', cmsParent:
11+
| { __typename: 'Convention', id: string, previewLiquid: string }
12+
| { __typename: 'RootSite', id: string, previewLiquid: string }
13+
};
1114

1215
export type PreviewMarkdownQueryVariables = Types.Exact<{
1316
markdown: Types.Scalars['String']['input'];
@@ -16,7 +19,10 @@ export type PreviewMarkdownQueryVariables = Types.Exact<{
1619
}>;
1720

1821

19-
export type PreviewMarkdownQueryData = { __typename: 'Query', cmsParent: { __typename: 'Convention', id: string, previewMarkdown: string } | { __typename: 'RootSite', id: string, previewMarkdown: string } };
22+
export type PreviewMarkdownQueryData = { __typename: 'Query', cmsParent:
23+
| { __typename: 'Convention', id: string, previewMarkdown: string }
24+
| { __typename: 'RootSite', id: string, previewMarkdown: string }
25+
};
2026

2127
export type PreviewNotifierLiquidQueryVariables = Types.Exact<{
2228
eventKey: Types.NotificationEventKey;

app/javascript/CmsAdmin/CmsContentGroupsAdmin/mutations.generated.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ export type CreateContentGroupMutationVariables = Types.Exact<{
88
}>;
99

1010

11-
export type CreateContentGroupMutationData = { __typename: 'Mutation', createCmsContentGroup: { __typename: 'CreateCmsContentGroupPayload', cms_content_group: { __typename: 'CmsContentGroup', id: string, name: string, current_ability_can_update: boolean, current_ability_can_delete: boolean, contents: Array<{ __typename: 'CmsLayout', id: string, name?: string | null } | { __typename: 'CmsPartial', id: string, name?: string | null } | { __typename: 'Page', id: string, name?: string | null }>, permissions: Array<{ __typename: 'Permission', id: string, permission: string, model: { __typename: 'CmsContentGroup', id: string, name: string } | { __typename: 'Convention', id: string, name: string } | { __typename: 'EventCategory', id: string, name: string, default_color?: string | null }, role: { __typename: 'OrganizationRole', id: string, name: string } | { __typename: 'StaffPosition', id: string, name: string } }> } } };
11+
export type CreateContentGroupMutationData = { __typename: 'Mutation', createCmsContentGroup: { __typename: 'CreateCmsContentGroupPayload', cms_content_group: { __typename: 'CmsContentGroup', id: string, name: string, current_ability_can_update: boolean, current_ability_can_delete: boolean, contents: Array<
12+
| { __typename: 'CmsLayout', id: string, name?: string | null }
13+
| { __typename: 'CmsPartial', id: string, name?: string | null }
14+
| { __typename: 'Page', id: string, name?: string | null }
15+
>, permissions: Array<{ __typename: 'Permission', id: string, permission: string, model:
16+
| { __typename: 'CmsContentGroup', id: string, name: string }
17+
| { __typename: 'Convention', id: string, name: string }
18+
| { __typename: 'EventCategory', id: string, name: string, default_color?: string | null }
19+
, role:
20+
| { __typename: 'OrganizationRole', id: string, name: string }
21+
| { __typename: 'StaffPosition', id: string, name: string }
22+
}> } } };
1223

1324
export type UpdateContentGroupMutationVariables = Types.Exact<{
1425
id: Types.Scalars['ID']['input'];
@@ -18,7 +29,18 @@ export type UpdateContentGroupMutationVariables = Types.Exact<{
1829
}>;
1930

2031

21-
export type UpdateContentGroupMutationData = { __typename: 'Mutation', updateCmsContentGroup: { __typename: 'UpdateCmsContentGroupPayload', cms_content_group: { __typename: 'CmsContentGroup', id: string, name: string, current_ability_can_update: boolean, current_ability_can_delete: boolean, contents: Array<{ __typename: 'CmsLayout', id: string, name?: string | null } | { __typename: 'CmsPartial', id: string, name?: string | null } | { __typename: 'Page', id: string, name?: string | null }>, permissions: Array<{ __typename: 'Permission', id: string, permission: string, model: { __typename: 'CmsContentGroup', id: string, name: string } | { __typename: 'Convention', id: string, name: string } | { __typename: 'EventCategory', id: string, name: string, default_color?: string | null }, role: { __typename: 'OrganizationRole', id: string, name: string } | { __typename: 'StaffPosition', id: string, name: string } }> } } };
32+
export type UpdateContentGroupMutationData = { __typename: 'Mutation', updateCmsContentGroup: { __typename: 'UpdateCmsContentGroupPayload', cms_content_group: { __typename: 'CmsContentGroup', id: string, name: string, current_ability_can_update: boolean, current_ability_can_delete: boolean, contents: Array<
33+
| { __typename: 'CmsLayout', id: string, name?: string | null }
34+
| { __typename: 'CmsPartial', id: string, name?: string | null }
35+
| { __typename: 'Page', id: string, name?: string | null }
36+
>, permissions: Array<{ __typename: 'Permission', id: string, permission: string, model:
37+
| { __typename: 'CmsContentGroup', id: string, name: string }
38+
| { __typename: 'Convention', id: string, name: string }
39+
| { __typename: 'EventCategory', id: string, name: string, default_color?: string | null }
40+
, role:
41+
| { __typename: 'OrganizationRole', id: string, name: string }
42+
| { __typename: 'StaffPosition', id: string, name: string }
43+
}> } } };
2244

2345
export type DeleteContentGroupMutationVariables = Types.Exact<{
2446
id: Types.Scalars['ID']['input'];

0 commit comments

Comments
 (0)