MCPcopy Create free account
hub / github.com/dailydotdev/apps / getSquadsCreatePrefillState

Function getSquadsCreatePrefillState

packages/webapp/lib/squadsCreatePrefill.ts:36–76  ·  view source on GitHub ↗
(
  query: ParsedUrlQuery,
  existingDraft: Partial<WriteForm> = {},
)

Source from the content-addressed store, hash-verified

34const hasValue = (value?: string): boolean => !!value?.trim();
35
36export const getSquadsCreatePrefillState = (
37 query: ParsedUrlQuery,
38 existingDraft: Partial<WriteForm> = {},
39): SquadsCreatePrefillState => {
40 const title = sanitizeParam(query.title, MAX_CREATE_POST_TITLE_LENGTH);
41 const body = sanitizeParam(query.body, MAX_CREATE_POST_BODY_LENGTH);
42 const link = sanitizeParam(query.link);
43 const hasShareQueryParam = !!getFirstQueryParam(query.share);
44 const hasPollQueryParam = !!getFirstQueryParam(query.poll);
45 const hasStandupQueryParam = !!getFirstQueryParam(query.standup);
46
47 const initialShareUrl = link && isValidHttpUrl(link) ? link : undefined;
48 const shouldOpenShare = !!initialShareUrl || hasShareQueryParam;
49 let initialDisplay: WriteFormTab | null = null;
50
51 if (hasStandupQueryParam) {
52 initialDisplay = WriteFormTab.Standup;
53 } else if (hasPollQueryParam) {
54 initialDisplay = WriteFormTab.Poll;
55 } else if (shouldOpenShare) {
56 initialDisplay = WriteFormTab.Share;
57 }
58
59 const initialDraft: Partial<WriteForm> = {};
60 if (!shouldOpenShare) {
61 if (title && !hasValue(existingDraft.title)) {
62 initialDraft.title = title;
63 }
64
65 if (body && !hasValue(existingDraft.content)) {
66 initialDraft.content = body;
67 }
68 }
69
70 return {
71 initialDisplay,
72 initialDraft,
73 initialShareUrl,
74 initialShareCommentary: shouldOpenShare ? body ?? title : undefined,
75 };
76};

Callers 2

CreatePostFunction · 0.90

Calls 4

getFirstQueryParamFunction · 0.90
isValidHttpUrlFunction · 0.90
sanitizeParamFunction · 0.85
hasValueFunction · 0.85

Tested by

no test coverage detected