Skip to content

Commit df70fbf

Browse files
committed
fix: build ci error
1 parent 95f4bb4 commit df70fbf

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

apps/desktop-v2/components/task-builder-dialog.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getCbRangesFromRegex,
3030
EXP_DUR_SLATE_TYPE,
3131
extractStartAt,
32+
extractDate,
3233
} from "../utils/supernova-task";
3334
import { Kbd } from "./kbd";
3435
import { Button } from "./button";
@@ -66,6 +67,7 @@ export const TaskBuilderDialog = (props: {
6667

6768
const handleEditorChange = (value: Descendant[]) => {
6869
const content = (value[0] as any).children[0].text as string;
70+
// extract the duration if any
6971
const extractedDuration = extractExpectedDuration(content);
7072
let duration: number | undefined = undefined;
7173
let newTitle = content;
@@ -82,6 +84,7 @@ export const TaskBuilderDialog = (props: {
8284
extractedDuration.match.index + extractedDuration.match[0].length
8385
);
8486
}
87+
// extract the start at time if any
8588
const extractedStartAt = extractStartAt(newTitle);
8689
let startTime: Date | undefined = undefined;
8790
if (extractedStartAt !== null) {
@@ -92,6 +95,8 @@ export const TaskBuilderDialog = (props: {
9295
extractedStartAt.match.index + extractedStartAt.match[0].length
9396
);
9497
}
98+
// extract the date if any
99+
const extractedDate = extractDate(newTitle);
95100

96101
setTaskEdit((prev) => ({
97102
...prev,

apps/desktop-v2/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = withSentryConfig(
1717
// Suppresses source map uploading logs during build
1818
silent: true,
1919
org: "supernova-0z",
20-
project: "javascript-nextjs",
20+
project: "desktop-web-app",
2121
},
2222
{
2323
// For all available options, see:

apps/desktop-v2/utils/supernova-task.ts

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ import { ISupernovaTask } from "@supernova/types";
55
export const START_AT_SLATE_TYPE = "startAt";
66
export const EXP_DUR_SLATE_TYPE = "expectedDuration";
77

8+
/**
9+
* gets the regex for expected duration
10+
* @returns the regex for expected duration
11+
*/
12+
export function getExpectedDurationRegex(): RegExp {
13+
return new RegExp(
14+
/\bfor\s*(\d+)\s*(?:(mins?|m|minutes?)|(hours?|hrs?|h))\s*\b\s*/gi
15+
);
16+
}
17+
18+
/**
19+
* gets the regex for start at
20+
* @returns the regex for start at
21+
*/
22+
export function getStartAtRegex(): RegExp {
23+
return new RegExp(
24+
/\b(?:start at|at|from)\s+(\d{1,2}(?::\d{2})?\s*(?:[APap]?[Mm]?))?\b/gi
25+
);
26+
}
27+
28+
export function getDateRegex(): RegExp {
29+
return new RegExp(
30+
/\b(?:tmr|tom|today|in (\d+) days|next week|in (\d+) weeks|tomorrow)\b/gi
31+
);
32+
}
33+
834
/**
935
* Extracts the expected duration from a text string.
1036
* @param text The text to extract the expected duration from.
@@ -19,9 +45,7 @@ export function extractExpectedDuration(
1945
text: string
2046
): { value: number; unit: "m" | "h"; match: RegExpExecArray } | null {
2147
// TODO: need to fix this local scope problem with the regexs somehow
22-
const expectedDurationRegex = new RegExp(
23-
/\bfor\s*(\d+)\s*(?:(mins?|m|minutes?)|(hours?|hrs?|h))\s*\b\s*/gi
24-
);
48+
const expectedDurationRegex = getExpectedDurationRegex();
2549
const match = expectedDurationRegex.exec(text);
2650
if (match === null) {
2751
return null;
@@ -47,9 +71,7 @@ export function extractStartAt(
4771
text: string
4872
): { value: Date; match: RegExpExecArray } | null {
4973
// TODO: need to fix this local scope problem with the regexs somehow
50-
const startAtRegex = new RegExp(
51-
/\b(?:start at|at|from)\s+(\d{1,2}(?::\d{2})?\s*(?:[APap]?[Mm]?))?\b/gi
52-
);
74+
const startAtRegex = getStartAtRegex();
5375
const match = startAtRegex.exec(text);
5476
if (match === null || match[1] === undefined) {
5577
return null;
@@ -83,6 +105,36 @@ export function extractStartAt(
83105
return { value: date, match };
84106
}
85107

108+
export function extractDate(
109+
text: string
110+
): { value: Date; match: RegExpExecArray } | null {
111+
const dateRegex = getDateRegex();
112+
const match = dateRegex.exec(text);
113+
if (match === null) {
114+
return null;
115+
}
116+
console.log(match);
117+
const date = new Date();
118+
switch (match[0]) {
119+
case "tomorrow":
120+
case "tmr":
121+
case "tom":
122+
date.setDate(date.getDate() + 1);
123+
break;
124+
case "today":
125+
date.setDate(date.getDate());
126+
break;
127+
case "next week":
128+
date.setDate(date.getDate() + 7);
129+
break;
130+
default:
131+
const days = parseInt(match[1]);
132+
date.setDate(date.getDate() + days);
133+
break;
134+
}
135+
return { value: date, match };
136+
}
137+
86138
/**
87139
* Creates Slate ranges from a regex.
88140
* @param regex the regex to create ranges from

packages/api-client/converters.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { Converter, SupernovaResponse, ISupernovaTask } from "@supernova/types";
1+
import {
2+
Converter,
3+
TSupernovaResponse,
4+
ISupernovaTask,
5+
} from "@supernova/types";
26

37
export const supernovaResponseConverter: Converter<
48
Response,
5-
Promise<SupernovaResponse>
9+
Promise<TSupernovaResponse>
610
> = {
711
convert: async (r) => {
812
const json = await r.json();

0 commit comments

Comments
 (0)