Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/dashboard/project/CollaboratorsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const owner = collaborators.find((c) => c.role === ProjectRole.OWNER);
const otherMembers = collaborators.filter((c) => c.role !== ProjectRole.OWNER);

const result: { type: "MEMBER" | "INVITE" | "EMPTY"; data: any; key: string }[] = [];

Check failure on line 37 in components/dashboard/project/CollaboratorsSettings.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

if (owner) result.push({ type: "MEMBER", data: owner, key: `member-${owner.user.id}` });
otherMembers.forEach((m) => result.push({ type: "MEMBER", data: m, key: `member-${m.user.id}` }));
Expand Down Expand Up @@ -87,7 +87,7 @@
<div className={styles.proGateBanner}>
<Lock size={14} />
<span>{t("proRequired")}</span>
<a href="/?settings=Profile" className={styles.proGateLink}>{t("upgrade")}</a>

Check failure on line 90 in components/dashboard/project/CollaboratorsSettings.tsx

View workflow job for this annotation

GitHub Actions / lint

Do not use an `<a>` element to navigate to `/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages
</div>
)}

Expand Down Expand Up @@ -150,7 +150,7 @@
if (res.ok) {
if (res.status !== 204) {
// If user left the project by himself, redirect him to home
const json = (await res.json()) as ApiResponse;
const json = (await res.json()) as ApiResponse<{ redirectUrl: string }>;
if (json.data && json.data.redirectUrl) {
closeDashboard();
redirect(json.data.redirectUrl);
Expand Down
8 changes: 4 additions & 4 deletions components/projects/CreateProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const CreateProjectPage = ({ setIsCreating }: Props) => {
body.poster = await cropImageBase64(selectedFile, 686, 1016);
}
const res = await createProject(user.id, body);
const json = (await res.json()) as ApiResponse;
if (res.ok) {
const json = (await res.json()) as ApiResponse<{ id: string }>;
if (res.ok && json.data) {
projectId = json.data.id;
}
} catch {
Expand Down Expand Up @@ -101,8 +101,8 @@ const CreateProjectPage = ({ setIsCreating }: Props) => {
}

const res = await createProject(user.id, body);
const json = (await res.json()) as ApiResponse;
if (!res.ok) {
const json = (await res.json()) as ApiResponse<{ id: string }>;
if (!res.ok || !json.data) {
setFormInfo({ content: json.message!, isError: true });
return;
}
Expand Down
82 changes: 45 additions & 37 deletions src/lib/adapters/fountain/fountain_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,16 @@ const tokenize = function (script: string) {
return tokens;
};

const inline: Record<string, string | ((s: string) => string | undefined)> = {
//note: '<span class="note">$1</span>',
interface InlineLexer {
(s: string): string | undefined;
}

interface Inline {
[key: string]: string | InlineLexer | undefined;
lexer: InlineLexer;
}

const inline: Inline = {
line_break: "<br />",

bold_italic_underline: '<span class="bold italic underline">$2</span>',
Expand All @@ -247,45 +255,45 @@ const inline: Record<string, string | ((s: string) => string | undefined)> = {
bold: '<span class="bold">$2</span>',
italic: '<span class="italic">$2</span>',
underline: '<span class="underline">$2</span>',
};

inline.lexer = function (s: string) {
if (!s) {
return;
}

const styles = [
"underline",
"italic",
"bold",
"bold_italic",
"italic_underline",
"bold_underline",
"bold_italic_underline",
];
let i = styles.length;
let style: string;
let match: RegExp;

s = s
.replace(regex.note_inline, inline.note as string)
.replace(/\\\*/g, "[star]")
.replace(/\\_/g, "[underline]")
.replace(/\n/g, inline.line_break as string);

while (i--) {
style = styles[i];
match = (regex as Record<string, RegExp>)[style];
lexer: (s: string) => {
if (!s) {
return;
}

if (match.test(s)) {
s = s.replace(match, inline[style] as string);
const styles = [
"underline",
"italic",
"bold",
"bold_italic",
"italic_underline",
"bold_underline",
"bold_italic_underline",
];
let i = styles.length;
let style: string;
let match: RegExp;

s = s
.replace(regex.note_inline, (inline.note as string) || "")
.replace(/\\\*/g, "[star]")
.replace(/\\_/g, "[underline]")
.replace(/\n/g, (inline.line_break as string) || "");

while (i--) {
style = styles[i];
match = (regex as Record<string, RegExp>)[style];

if (match.test(s)) {
s = s.replace(match, (inline[style] as string) || "");
}
}
}

return s
.replace(/\[star\]/g, "*")
.replace(/\[underline\]/g, "_")
.trim();
return s
.replace(/\[star\]/g, "*")
.replace(/\[underline\]/g, "_")
.trim();
},
};

const parse = function (script: string, toks?: boolean | FountainCallback, callback?: FountainCallback): FountainOutput {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/import/import-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ async function createRemoteProject(userId: string, title: string, description?:
};

const res = await createProject(userId, body);
const json = (await res.json()) as ApiResponse;
const json = (await res.json()) as ApiResponse<{ id: string }>;

if (!res.ok) {
if (!res.ok || !json.data) {
throw new Error(json.message || "Failed to create project");
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/spellcheck/spellcheck.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ self.onmessage = async (e: MessageEvent<SpellWorkerRequest>) => {
post({ type: "ERROR", error: "Hunspell not initialized" });
break;
}
const misspelled = msg.words.filter((w) => !hunspell.spell(w));
const h = hunspell;
const misspelled = msg.words.filter((w) => !h.spell(w));
post({ type: "CHECK_RESULT", id: msg.id, misspelled });
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/titlepage/nodes/text-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const TitlePageTextNode = Node.create({
return "left";
},
renderHTML: (attributes: Record<string, unknown>) => {
const cls = ALIGN_CLASSES[attributes.textAlign] || ALIGN_CLASSES.left;
const alignment = (attributes.textAlign as string) || "left";
const cls = ALIGN_CLASSES[alignment] || ALIGN_CLASSES.left;
return { class: cls };
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function getCollabHttpUrl(path: string): string {
export const getCloudToken = async (projectId: string): Promise<{ token: string | null; status: number }> => {
const res = await request(`/api/projects/${projectId}/cloud-token`, "GET");
if (res.ok) {
const { data: token } = (await res.json()) as ApiResponse;
return { token, status: res.status };
const { data: token } = (await res.json()) as ApiResponse<string>;
return { token: token ?? null, status: res.status };
}
return { token: null, status: res.status };
};
Expand Down
Loading