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

Function getSquadsCreatePrefillState

packages/webapp/lib/squadsCreatePrefill.ts:36–73  ·  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
46 const initialShareUrl = link && isValidHttpUrl(link) ? link : undefined;
47 const shouldOpenShare = !!initialShareUrl || hasShareQueryParam;
48 let initialDisplay: WriteFormTab | null = null;
49
50 if (hasPollQueryParam) {
51 initialDisplay = WriteFormTab.Poll;
52 } else if (shouldOpenShare) {
53 initialDisplay = WriteFormTab.Share;
54 }
55
56 const initialDraft: Partial<WriteForm> = {};
57 if (!shouldOpenShare) {
58 if (title && !hasValue(existingDraft.title)) {
59 initialDraft.title = title;
60 }
61
62 if (body && !hasValue(existingDraft.content)) {
63 initialDraft.content = body;
64 }
65 }
66
67 return {
68 initialDisplay,
69 initialDraft,
70 initialShareUrl,
71 initialShareCommentary: shouldOpenShare ? (body ?? title) : undefined,
72 };
73};

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