Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 8e903bc

Browse files
authored
Merge pull request #4564 from withspectrum/plaintext-thread-editor
Move thread editor to plaintext
2 parents 9bad727 + aaefe6f commit 8e903bc

File tree

41 files changed

+1448
-1160
lines changed

Some content is hidden

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

41 files changed

+1448
-1160
lines changed

api/mutations/files/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @flow
2+
import uploadImage from './uploadImage';
3+
4+
module.exports = {
5+
Mutation: {
6+
uploadImage,
7+
},
8+
};

api/mutations/files/uploadImage.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @flow
2+
import { isAuthedResolver } from '../../utils/permissions';
3+
import { uploadImage } from '../../utils/file-storage';
4+
import type { EntityTypes } from 'shared/types';
5+
import type { GraphQLContext } from '../../';
6+
import type { FileUpload } from 'shared/types';
7+
import { signImageUrl } from 'shared/imgix';
8+
9+
type Args = {
10+
input: {
11+
image: FileUpload,
12+
type: EntityTypes,
13+
id?: string,
14+
},
15+
};
16+
17+
export default isAuthedResolver(
18+
async (_: void, { input }: Args, { loaders }: GraphQLContext) => {
19+
const { image, type, id } = input;
20+
const url = await uploadImage(image, type, id || 'draft');
21+
return await signImageUrl(url);
22+
}
23+
);

api/mutations/thread/publishThread.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// @flow
22
const debug = require('debug')('api:mutations:thread:publish-thread');
33
import stringSimilarity from 'string-similarity';
4-
import { convertToRaw } from 'draft-js';
4+
import {
5+
convertToRaw,
6+
convertFromRaw,
7+
EditorState,
8+
SelectionState,
9+
} from 'draft-js';
510
import { stateFromMarkdown } from 'draft-js-import-markdown';
611
import type { GraphQLContext } from '../../';
712
import UserError from '../../utils/UserError';
813
import { uploadImage } from '../../utils/file-storage';
14+
import processThreadContent from 'shared/draft-utils/process-thread-content';
915
import {
1016
publishThread,
1117
editThread,
@@ -68,22 +74,11 @@ export default requireAuth(
6874
);
6975
}
7076

71-
if (type === 'TEXT') {
72-
type = 'DRAFTJS';
73-
if (thread.content.body) {
74-
thread.content.body = JSON.stringify(
75-
convertToRaw(
76-
stateFromMarkdown(thread.content.body, {
77-
parserOptions: {
78-
breaks: true,
79-
},
80-
})
81-
)
82-
);
83-
}
77+
if (thread.content.body) {
78+
thread.content.body = processThreadContent(type, thread.content.body);
8479
}
8580

86-
thread.type = type;
81+
thread.type = 'DRAFTJS';
8782

8883
const [
8984
currentUserChannelPermissions,

api/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const notificationMutations = require('./mutations/notification');
5656
const userMutations = require('./mutations/user');
5757
const metaMutations = require('./mutations/meta');
5858
const communityMemberMutations = require('./mutations/communityMember');
59+
const fileMutations = require('./mutations/files');
5960

6061
const messageSubscriptions = require('./subscriptions/message');
6162
const notificationSubscriptions = require('./subscriptions/notification');
@@ -125,6 +126,7 @@ const resolvers = merge(
125126
userMutations,
126127
metaMutations,
127128
communityMemberMutations,
129+
fileMutations,
128130
// subscriptions
129131
messageSubscriptions,
130132
notificationSubscriptions,

api/types/general.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ const general = /* GraphQL */ `
7676
createdAt: String
7777
status: String
7878
}
79+
80+
enum EntityTypes {
81+
communities
82+
channels
83+
users
84+
threads
85+
}
86+
87+
input UploadImageInput {
88+
image: Upload!
89+
type: EntityTypes!
90+
id: String
91+
}
92+
93+
extend type Mutation {
94+
uploadImage(input: UploadImageInput!): String
95+
@rateLimit(max: 20, window: "20m")
96+
}
7997
`;
8098

8199
module.exports = general;

cypress/integration/channel/view/composer_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('renders composer for logged in members', () => {
3333

3434
cy.get('[data-cy="thread-composer-placeholder"]').click();
3535

36-
cy.get('[data-cy="thread-composer"]').should('be.visible');
36+
cy.get('[data-cy="rich-text-editor"]').should('be.visible');
3737
});
3838
});
3939

cypress/integration/community/view/profile_spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ describe('private community signed in with permissions', () => {
268268
.filter(channel => !channel.isPrivate)
269269
.filter(channel => !channel.deletedAt)
270270
.forEach(channel => {
271-
cy.contains(channel.name)
271+
cy.get('[data-cy="channel-list"]')
272+
.contains(channel.name)
272273
.scrollIntoView()
273274
.should('be.visible');
274275
});

cypress/integration/thread/action_bar_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('action bar renders', () => {
189189
cy.get('[data-cy="thread-dropdown-edit"]').click();
190190
cy.get('[data-cy="save-thread-edit-button"]').should('be.visible');
191191
const title = 'Some new thread';
192-
cy.get('[data-cy="rich-text-editor"]').should('be.visible');
192+
cy.get('[data-cy="rich-text-editor"].markdown').should('be.visible');
193193
cy.get('[data-cy="thread-editor-title-input"]')
194194
.clear()
195195
.type(title);
@@ -201,7 +201,7 @@ describe('action bar renders', () => {
201201
cy.get('[data-cy="thread-dropdown-edit"]').click();
202202
cy.get('[data-cy="save-thread-edit-button"]').should('be.visible');
203203
const originalTitle = 'The first thread! 🎉';
204-
cy.get('[data-cy="rich-text-editor"]').should('be.visible');
204+
cy.get('[data-cy="rich-text-editor"].markdown').should('be.visible');
205205
cy.get('[data-cy="thread-editor-title-input"]')
206206
.clear()
207207
.type(originalTitle);

cypress/integration/thread_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe('/new/thread', () => {
456456
cy.get('[data-cy="composer-channel-selector"]').should('be.visible');
457457
// Type title and body
458458
cy.get('[data-cy="composer-title-input"]').type(title);
459-
cy.get('[contenteditable="true"]').type(body);
459+
cy.get('[data-cy="rich-text-editor"]').type(body);
460460
cy.get('[data-cy="composer-publish-button"]').click();
461461
cy.location('pathname').should('contain', 'thread');
462462
cy.get('[data-cy="thread-view"]');
@@ -472,12 +472,12 @@ describe('/new/thread', () => {
472472
cy.get('[data-cy="composer-channel-selector"]').should('be.visible');
473473
// Type title and body
474474
cy.get('[data-cy="composer-title-input"]').type(title);
475-
cy.get('[contenteditable="true"]').type(body);
475+
cy.get('[data-cy="rich-text-editor"]').type(body);
476476
/////need time as our localstorage is not set
477477
cy.wait(1000);
478478
cy.reload();
479479

480480
cy.get('[data-cy="composer-title-input"]').contains(title);
481-
cy.get('[contenteditable="true"]').contains(body);
481+
cy.get('[data-cy="rich-text-editor"]').contains(body);
482482
});
483483
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// flow-typed signature: a5a6c5ef2495cde307215470bb3dd2b5
2+
// flow-typed version: <<STUB>>/react-dropzone_v8.0.3/flow_v0.66.0
3+
4+
/**
5+
* This is an autogenerated libdef stub for:
6+
*
7+
* 'react-dropzone'
8+
*
9+
* Fill this stub out by replacing all the `any` types.
10+
*
11+
* Once filled out, we encourage you to share your work with the
12+
* community by sending a pull request to:
13+
* https://github.com/flowtype/flow-typed
14+
*/
15+
16+
declare module 'react-dropzone' {
17+
declare module.exports: any;
18+
}
19+
20+
/**
21+
* We include stubs for each file inside this npm package in case you need to
22+
* require those files directly. Feel free to delete any files that aren't
23+
* needed.
24+
*/
25+
declare module 'react-dropzone/commitlint.config' {
26+
declare module.exports: any;
27+
}
28+
29+
declare module 'react-dropzone/dist/es/index' {
30+
declare module.exports: any;
31+
}
32+
33+
declare module 'react-dropzone/dist/es/utils/index' {
34+
declare module.exports: any;
35+
}
36+
37+
declare module 'react-dropzone/dist/es/utils/styles' {
38+
declare module.exports: any;
39+
}
40+
41+
declare module 'react-dropzone/dist/index' {
42+
declare module.exports: any;
43+
}
44+
45+
declare module 'react-dropzone/rollup.config' {
46+
declare module.exports: any;
47+
}
48+
49+
declare module 'react-dropzone/src/index' {
50+
declare module.exports: any;
51+
}
52+
53+
declare module 'react-dropzone/src/index.spec' {
54+
declare module.exports: any;
55+
}
56+
57+
declare module 'react-dropzone/src/utils/index' {
58+
declare module.exports: any;
59+
}
60+
61+
declare module 'react-dropzone/src/utils/index.spec' {
62+
declare module.exports: any;
63+
}
64+
65+
declare module 'react-dropzone/src/utils/styles' {
66+
declare module.exports: any;
67+
}
68+
69+
declare module 'react-dropzone/styleguide.config' {
70+
declare module.exports: any;
71+
}
72+
73+
declare module 'react-dropzone/testSetup' {
74+
declare module.exports: any;
75+
}
76+
77+
// Filename aliases
78+
declare module 'react-dropzone/commitlint.config.js' {
79+
declare module.exports: $Exports<'react-dropzone/commitlint.config'>;
80+
}
81+
declare module 'react-dropzone/dist/es/index.js' {
82+
declare module.exports: $Exports<'react-dropzone/dist/es/index'>;
83+
}
84+
declare module 'react-dropzone/dist/es/utils/index.js' {
85+
declare module.exports: $Exports<'react-dropzone/dist/es/utils/index'>;
86+
}
87+
declare module 'react-dropzone/dist/es/utils/styles.js' {
88+
declare module.exports: $Exports<'react-dropzone/dist/es/utils/styles'>;
89+
}
90+
declare module 'react-dropzone/dist/index.js' {
91+
declare module.exports: $Exports<'react-dropzone/dist/index'>;
92+
}
93+
declare module 'react-dropzone/rollup.config.js' {
94+
declare module.exports: $Exports<'react-dropzone/rollup.config'>;
95+
}
96+
declare module 'react-dropzone/src/index.js' {
97+
declare module.exports: $Exports<'react-dropzone/src/index'>;
98+
}
99+
declare module 'react-dropzone/src/index.spec.js' {
100+
declare module.exports: $Exports<'react-dropzone/src/index.spec'>;
101+
}
102+
declare module 'react-dropzone/src/utils/index.js' {
103+
declare module.exports: $Exports<'react-dropzone/src/utils/index'>;
104+
}
105+
declare module 'react-dropzone/src/utils/index.spec.js' {
106+
declare module.exports: $Exports<'react-dropzone/src/utils/index.spec'>;
107+
}
108+
declare module 'react-dropzone/src/utils/styles.js' {
109+
declare module.exports: $Exports<'react-dropzone/src/utils/styles'>;
110+
}
111+
declare module 'react-dropzone/styleguide.config.js' {
112+
declare module.exports: $Exports<'react-dropzone/styleguide.config'>;
113+
}
114+
declare module 'react-dropzone/testSetup.js' {
115+
declare module.exports: $Exports<'react-dropzone/testSetup'>;
116+
}

0 commit comments

Comments
 (0)