Skip to content

Commit 0ed7291

Browse files
committed
feat: convert to object
1 parent 019baa8 commit 0ed7291

File tree

23 files changed

+291
-187
lines changed

23 files changed

+291
-187
lines changed

apps/frontend/src/components/new-launch/providers/bluesky/bluesky.provider.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const SettingsComponent = () => {
1010
return <ThreadFinisher />;
1111
};
1212

13-
export default withProvider(
14-
PostComment.POST,
15-
SettingsComponent,
16-
undefined,
17-
undefined,
18-
async (posts) => {
13+
export default withProvider({
14+
postComment: PostComment.POST,
15+
minimumCharacters: [],
16+
SettingsComponent: SettingsComponent,
17+
CustomPreviewComponent: undefined,
18+
dto: undefined,
19+
checkValidity: async (posts) => {
1920
if (
2021
posts.some(
2122
(p) => p.some((a) => a.path.indexOf('mp4') > -1) && p.length > 1
@@ -29,5 +30,5 @@ export default withProvider(
2930
}
3031
return true;
3132
},
32-
300
33-
);
33+
maximumCharacters: 300,
34+
});

apps/frontend/src/components/new-launch/providers/devto/devto.provider.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client';
22

33
import { FC } from 'react';
4-
import { PostComment, withProvider } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
4+
import {
5+
PostComment,
6+
withProvider,
7+
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
58
import { DevToSettingsDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/dev.to.settings.dto';
69
import { Input } from '@gitroom/react/form/input';
710
import { MediaComponent } from '@gitroom/frontend/components/media/media.component';
@@ -83,4 +86,12 @@ const DevtoSettings: FC = () => {
8386
</>
8487
);
8588
};
86-
export default withProvider(PostComment.COMMENT, DevtoSettings, DevtoPreview, DevToSettingsDto);
89+
export default withProvider({
90+
postComment: PostComment.COMMENT,
91+
minimumCharacters: [],
92+
SettingsComponent: DevtoSettings,
93+
CustomPreviewComponent: DevtoPreview,
94+
dto: DevToSettingsDto,
95+
checkValidity: undefined,
96+
maximumCharacters: undefined,
97+
});
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use client';
22

3-
import { PostComment, withProvider } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
3+
import {
4+
PostComment,
5+
withProvider,
6+
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
47
import { FC } from 'react';
58
import { DiscordDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/discord.dto';
69
import { DiscordChannelSelect } from '@gitroom/frontend/components/new-launch/providers/discord/discord.channel.select';
@@ -13,11 +16,12 @@ const DiscordComponent: FC = () => {
1316
</div>
1417
);
1518
};
16-
export default withProvider(
17-
PostComment.COMMENT,
18-
DiscordComponent,
19-
undefined,
20-
DiscordDto,
21-
undefined,
22-
1980
23-
);
19+
export default withProvider({
20+
postComment: PostComment.COMMENT,
21+
minimumCharacters: [],
22+
SettingsComponent: DiscordComponent,
23+
CustomPreviewComponent: undefined,
24+
dto: DiscordDto,
25+
checkValidity: undefined,
26+
maximumCharacters: 1980,
27+
});

apps/frontend/src/components/new-launch/providers/dribbble/dribbble.provider.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ const DribbbleSettings: FC = () => {
1818
</div>
1919
);
2020
};
21-
export default withProvider(
22-
PostComment.COMMENT,
23-
DribbbleSettings,
24-
undefined,
25-
DribbbleDto,
26-
async ([firstItem, ...otherItems]) => {
21+
export default withProvider({
22+
postComment: PostComment.COMMENT,
23+
minimumCharacters: [],
24+
SettingsComponent: DribbbleSettings,
25+
CustomPreviewComponent: undefined,
26+
dto: DribbbleDto,
27+
checkValidity: async ([firstItem, ...otherItems]) => {
2728
const isMp4 = firstItem?.find((item) => item.path.indexOf('mp4') > -1);
2829
if (firstItem.length !== 1) {
2930
return 'Requires one item';
@@ -50,5 +51,5 @@ export default withProvider(
5051
}
5152
return 'Invalid image size. Requires 400x300 or 800x600 px images.';
5253
},
53-
40000
54-
);
54+
maximumCharacters: 40000,
55+
});
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
'use client';
22

3-
import { PostComment, withProvider } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
4-
export default withProvider(PostComment.COMMENT,null, undefined, undefined, undefined, 63206);
3+
import {
4+
PostComment,
5+
withProvider,
6+
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
7+
export default withProvider({
8+
postComment: PostComment.COMMENT,
9+
minimumCharacters: [],
10+
SettingsComponent: null,
11+
CustomPreviewComponent: undefined,
12+
dto: undefined,
13+
checkValidity: undefined,
14+
maximumCharacters: 63206,
15+
});

apps/frontend/src/components/new-launch/providers/hashnode/hashnode.provider.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client';
22

33
import { FC } from 'react';
4-
import { PostComment, withProvider } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
4+
import {
5+
PostComment,
6+
withProvider,
7+
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
58
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
69
import { Input } from '@gitroom/react/form/input';
710
import { HashnodePublications } from '@gitroom/frontend/components/new-launch/providers/hashnode/hashnode.publications';
@@ -85,9 +88,12 @@ const HashnodeSettings: FC = () => {
8588
</>
8689
);
8790
};
88-
export default withProvider(
89-
PostComment.COMMENT,
90-
HashnodeSettings,
91-
HashnodePreview,
92-
HashnodeSettingsDto
93-
);
91+
export default withProvider({
92+
postComment: PostComment.COMMENT,
93+
minimumCharacters: [],
94+
SettingsComponent: HashnodeSettings,
95+
CustomPreviewComponent: HashnodePreview,
96+
dto: HashnodeSettingsDto,
97+
checkValidity: undefined,
98+
maximumCharacters: undefined,
99+
});

apps/frontend/src/components/new-launch/providers/high.order.provider.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,25 @@ class Empty {
3030
export enum PostComment {
3131
ALL,
3232
POST,
33-
COMMENT
33+
COMMENT,
3434
}
3535

36-
export const withProvider = function <T extends object>(
37-
postComment: PostComment,
36+
interface CharacterCondition {
37+
format: 'no-pictures' | 'with-pictures';
38+
type: 'post' | 'comment';
39+
maximumCharacters: number;
40+
}
41+
42+
export const withProvider = function <T extends object>(params: {
43+
postComment: PostComment;
44+
minimumCharacters: CharacterCondition[];
3845
SettingsComponent: FC<{
3946
values?: any;
40-
}> | null,
47+
}> | null;
4148
CustomPreviewComponent?: FC<{
4249
maximumCharacters?: number;
43-
}>,
44-
dto?: any,
50+
}>;
51+
dto?: any;
4552
checkValidity?: (
4653
value: Array<
4754
Array<{
@@ -50,9 +57,18 @@ export const withProvider = function <T extends object>(
5057
>,
5158
settings: T,
5259
additionalSettings: any
53-
) => Promise<string | true>,
54-
maximumCharacters?: number | ((settings: any) => number)
55-
) {
60+
) => Promise<string | true>;
61+
maximumCharacters?: number | ((settings: any) => number);
62+
}) {
63+
const {
64+
postComment,
65+
SettingsComponent,
66+
CustomPreviewComponent,
67+
dto,
68+
checkValidity,
69+
maximumCharacters,
70+
} = params;
71+
5672
return forwardRef((props: { id: string }, ref) => {
5773
const t = useT();
5874
const fetch = useFetch();
@@ -245,7 +261,8 @@ export const withProvider = function <T extends object>(
245261
)}
246262
</div>
247263

248-
{(tab === 0 || (!SettingsComponent && !data?.internalPlugs?.length)) &&
264+
{(tab === 0 ||
265+
(!SettingsComponent && !data?.internalPlugs?.length)) &&
249266
!value?.[0]?.content?.length && (
250267
<div>
251268
{t(
@@ -254,7 +271,8 @@ export const withProvider = function <T extends object>(
254271
)}
255272
</div>
256273
)}
257-
{(tab === 0 || (!SettingsComponent && !data?.internalPlugs?.length)) &&
274+
{(tab === 0 ||
275+
(!SettingsComponent && !data?.internalPlugs?.length)) &&
258276
!!value?.[0]?.content?.length &&
259277
(CustomPreviewComponent ? (
260278
<CustomPreviewComponent

apps/frontend/src/components/new-launch/providers/instagram/instagram.collaborators.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ const InstagramCollaborators: FC<{
5353
</>
5454
);
5555
};
56-
export default withProvider<InstagramDto>(
57-
PostComment.COMMENT,
58-
InstagramCollaborators,
59-
undefined,
60-
InstagramDto,
61-
async ([firstPost, ...otherPosts], settings) => {
56+
export default withProvider<InstagramDto>({
57+
postComment: PostComment.COMMENT,
58+
minimumCharacters: [],
59+
SettingsComponent: InstagramCollaborators,
60+
CustomPreviewComponent: undefined,
61+
dto: InstagramDto,
62+
checkValidity: async ([firstPost, ...otherPosts], settings) => {
6263
if (!firstPost.length) {
6364
return 'Should have at least one media';
6465
}
@@ -90,5 +91,5 @@ export default withProvider<InstagramDto>(
9091
}
9192
return true;
9293
},
93-
2200
94-
);
94+
maximumCharacters: 2200,
95+
});

apps/frontend/src/components/new-launch/providers/lemmy/lemmy.provider.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client';
22

33
import { FC, useCallback } from 'react';
4-
import { PostComment, withProvider } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
4+
import {
5+
PostComment,
6+
withProvider,
7+
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
58
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
69
import { useFieldArray } from 'react-hook-form';
710
import { Button } from '@gitroom/react/form/button';
@@ -63,12 +66,13 @@ const LemmySettings: FC = () => {
6366
</>
6467
);
6568
};
66-
export default withProvider(
67-
PostComment.COMMENT,
68-
LemmySettings,
69-
undefined,
70-
LemmySettingsDto,
71-
async (items) => {
69+
export default withProvider({
70+
postComment: PostComment.COMMENT,
71+
minimumCharacters: [],
72+
SettingsComponent: LemmySettings,
73+
CustomPreviewComponent: undefined,
74+
dto: LemmySettingsDto,
75+
checkValidity: async (items) => {
7276
const [firstItems] = items;
7377
if (
7478
firstItems.length &&
@@ -81,5 +85,5 @@ export default withProvider(
8185
}
8286
return true;
8387
},
84-
10000
85-
);
88+
maximumCharacters: 10000,
89+
});

apps/frontend/src/components/new-launch/providers/linkedin/linkedin.provider.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ const LinkedInSettings = () => {
2525
</div>
2626
);
2727
};
28-
export default withProvider<LinkedinDto>(
29-
PostComment.COMMENT,
30-
LinkedInSettings,
31-
undefined,
32-
LinkedinDto,
33-
async (posts, vals) => {
28+
export default withProvider<LinkedinDto>({
29+
postComment: PostComment.COMMENT,
30+
minimumCharacters: [],
31+
SettingsComponent: LinkedInSettings,
32+
CustomPreviewComponent: undefined,
33+
dto: LinkedinDto,
34+
checkValidity: async (posts, vals) => {
3435
const [firstPost, ...restPosts] = posts;
3536

3637
if (
@@ -52,5 +53,5 @@ export default withProvider<LinkedinDto>(
5253
}
5354
return true;
5455
},
55-
3000
56-
);
56+
maximumCharacters: 3000,
57+
});

0 commit comments

Comments
 (0)