Skip to content

Commit ab28ab0

Browse files
committed
feat: add user setting for which default post type to use
1 parent 984c4bd commit ab28ab0

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

__tests__/__snapshots__/settings.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Object {
1010
"enableCardAnimations": true,
1111
"flags": Object {
1212
"clickbaitShieldEnabled": null,
13+
"defaultWriteTab": null,
1314
"sidebarBookmarksExpanded": null,
1415
"sidebarCustomFeedsExpanded": null,
1516
"sidebarOtherExpanded": null,
@@ -44,6 +45,7 @@ Object {
4445
"enableCardAnimations": true,
4546
"flags": Object {
4647
"clickbaitShieldEnabled": null,
48+
"defaultWriteTab": null,
4749
"sidebarBookmarksExpanded": null,
4850
"sidebarCustomFeedsExpanded": null,
4951
"sidebarOtherExpanded": null,
@@ -80,6 +82,7 @@ Object {
8082
"enableCardAnimations": true,
8183
"flags": Object {
8284
"clickbaitShieldEnabled": null,
85+
"defaultWriteTab": null,
8386
"sidebarBookmarksExpanded": null,
8487
"sidebarCustomFeedsExpanded": null,
8588
"sidebarOtherExpanded": null,
@@ -116,6 +119,7 @@ Object {
116119
"enableCardAnimations": true,
117120
"flags": Object {
118121
"clickbaitShieldEnabled": null,
122+
"defaultWriteTab": null,
119123
"sidebarBookmarksExpanded": null,
120124
"sidebarCustomFeedsExpanded": null,
121125
"sidebarOtherExpanded": null,

__tests__/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('mutation updateUserSettings', () => {
119119
sidebarSquadExpanded
120120
sidebarBookmarksExpanded
121121
clickbaitShieldEnabled
122+
defaultWriteTab
122123
}
123124
}
124125
}`;
@@ -154,6 +155,7 @@ describe('mutation updateUserSettings', () => {
154155
sidebarSquadExpanded: null,
155156
sidebarBookmarksExpanded: null,
156157
clickbaitShieldEnabled: null,
158+
defaultWriteTab: null,
157159
});
158160
});
159161

@@ -172,6 +174,7 @@ describe('mutation updateUserSettings', () => {
172174
sidebarSquadExpanded: null,
173175
sidebarBookmarksExpanded: null,
174176
clickbaitShieldEnabled: null,
177+
defaultWriteTab: null,
175178
});
176179

177180
const userSettings = await con.getRepository(Settings).findOneOrFail({
@@ -307,6 +310,7 @@ describe('mutation updateUserSettings', () => {
307310
sidebarSquadExpanded: null,
308311
sidebarBookmarksExpanded: null,
309312
clickbaitShieldEnabled: null,
313+
defaultWriteTab: null,
310314
});
311315
});
312316

@@ -341,6 +345,7 @@ describe('mutation updateUserSettings', () => {
341345
sidebarSquadExpanded: null,
342346
sidebarBookmarksExpanded: null,
343347
clickbaitShieldEnabled: null,
348+
defaultWriteTab: null,
344349
});
345350
});
346351

src/entity/Settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export enum ChecklistViewState {
2020
Hidden = 'hidden',
2121
}
2222

23+
export enum DefaultWriteTab {
24+
Share = 'Share',
25+
NewPost = 'NewPost',
26+
Poll = 'Poll',
27+
}
28+
2329
export type SettingsFlags = Partial<{
2430
sidebarSquadExpanded: boolean;
2531
sidebarCustomFeedsExpanded: boolean;
@@ -30,6 +36,7 @@ export type SettingsFlags = Partial<{
3036
prompt: object;
3137
timezoneMismatchIgnore: string;
3238
lastPrompt: string;
39+
defaultWriteTab: DefaultWriteTab;
3340
}>;
3441

3542
export type SettingsFlagsPublic = Pick<
@@ -43,6 +50,7 @@ export type SettingsFlagsPublic = Pick<
4350
| 'prompt'
4451
| 'timezoneMismatchIgnore'
4552
| 'lastPrompt'
53+
| 'defaultWriteTab'
4654
>;
4755

4856
@Entity()
@@ -143,5 +151,6 @@ export const SETTINGS_DEFAULT = {
143151
sidebarResourcesExpanded: true,
144152
sidebarBookmarksExpanded: true,
145153
clickbaitShieldEnabled: true,
154+
defaultWriteTab: DefaultWriteTab.NewPost,
146155
},
147156
};

src/schema/settings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AuthContext, BaseContext } from '../Context';
44
import {
55
CampaignCtaPlacement,
66
ChecklistViewState,
7+
DefaultWriteTab,
78
Settings,
89
SETTINGS_DEFAULT,
910
SettingsFlagsPublic,
@@ -52,10 +53,12 @@ interface GQLUpdateSettingsInput extends Partial<GQLSettings> {
5253
campaignCtaPlacement?: CampaignCtaPlacement;
5354
customLinks?: string[];
5455
optOutReadingStreak?: boolean;
56+
defaultWriteTab?: DefaultWriteTab;
5557
}
5658

5759
export const typeDefs = /* GraphQL */ `
5860
${toGQLEnum(ChecklistViewState, 'ChecklistViewState')}
61+
${toGQLEnum(DefaultWriteTab, 'DefaultWriteTab')}
5962
6063
type SettingsFlagsPublic {
6164
sidebarSquadExpanded: Boolean
@@ -66,6 +69,7 @@ export const typeDefs = /* GraphQL */ `
6669
clickbaitShieldEnabled: Boolean
6770
timezoneMismatchIgnore: String
6871
lastPrompt: String
72+
defaultWriteTab: DefaultWriteTab
6973
}
7074
7175
input SettingsFlagsPublicInput {
@@ -78,6 +82,7 @@ export const typeDefs = /* GraphQL */ `
7882
prompt: JSONObject
7983
timezoneMismatchIgnore: String
8084
lastPrompt: String
85+
defaultWriteTab: DefaultWriteTab
8186
}
8287
8388
"""
@@ -367,6 +372,13 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
367372
throw new ValidationError(`Invalid value for 'campaignCtaPlacement'`);
368373
}
369374

375+
if (
376+
data?.flags?.defaultWriteTab &&
377+
!Object.values(DefaultWriteTab).includes(data.flags.defaultWriteTab)
378+
) {
379+
throw new ValidationError(`Invalid value for 'defaultWriteTab'`);
380+
}
381+
370382
const promptSchema = z.record(z.string(), z.boolean());
371383
const result = promptSchema.safeParse(data.flags?.prompt);
372384

0 commit comments

Comments
 (0)