Skip to content

Commit

Permalink
fix: build ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvincent committed Sep 26, 2023
1 parent 95f4bb4 commit df70fbf
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
5 changes: 5 additions & 0 deletions apps/desktop-v2/components/task-builder-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getCbRangesFromRegex,
EXP_DUR_SLATE_TYPE,
extractStartAt,
extractDate,
} from "../utils/supernova-task";
import { Kbd } from "./kbd";
import { Button } from "./button";
Expand Down Expand Up @@ -66,6 +67,7 @@ export const TaskBuilderDialog = (props: {

const handleEditorChange = (value: Descendant[]) => {
const content = (value[0] as any).children[0].text as string;
// extract the duration if any
const extractedDuration = extractExpectedDuration(content);
let duration: number | undefined = undefined;
let newTitle = content;
Expand All @@ -82,6 +84,7 @@ export const TaskBuilderDialog = (props: {
extractedDuration.match.index + extractedDuration.match[0].length
);
}
// extract the start at time if any
const extractedStartAt = extractStartAt(newTitle);
let startTime: Date | undefined = undefined;
if (extractedStartAt !== null) {
Expand All @@ -92,6 +95,8 @@ export const TaskBuilderDialog = (props: {
extractedStartAt.match.index + extractedStartAt.match[0].length
);
}
// extract the date if any
const extractedDate = extractDate(newTitle);

setTaskEdit((prev) => ({
...prev,
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = withSentryConfig(
// Suppresses source map uploading logs during build
silent: true,
org: "supernova-0z",
project: "javascript-nextjs",
project: "desktop-web-app",
},
{
// For all available options, see:
Expand Down
64 changes: 58 additions & 6 deletions apps/desktop-v2/utils/supernova-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ import { ISupernovaTask } from "@supernova/types";
export const START_AT_SLATE_TYPE = "startAt";
export const EXP_DUR_SLATE_TYPE = "expectedDuration";

/**
* gets the regex for expected duration
* @returns the regex for expected duration
*/
export function getExpectedDurationRegex(): RegExp {
return new RegExp(
/\bfor\s*(\d+)\s*(?:(mins?|m|minutes?)|(hours?|hrs?|h))\s*\b\s*/gi
);
}

/**
* gets the regex for start at
* @returns the regex for start at
*/
export function getStartAtRegex(): RegExp {
return new RegExp(
/\b(?:start at|at|from)\s+(\d{1,2}(?::\d{2})?\s*(?:[APap]?[Mm]?))?\b/gi
);
}

export function getDateRegex(): RegExp {
return new RegExp(
/\b(?:tmr|tom|today|in (\d+) days|next week|in (\d+) weeks|tomorrow)\b/gi
);
}

/**
* Extracts the expected duration from a text string.
* @param text The text to extract the expected duration from.
Expand All @@ -19,9 +45,7 @@ export function extractExpectedDuration(
text: string
): { value: number; unit: "m" | "h"; match: RegExpExecArray } | null {
// TODO: need to fix this local scope problem with the regexs somehow
const expectedDurationRegex = new RegExp(
/\bfor\s*(\d+)\s*(?:(mins?|m|minutes?)|(hours?|hrs?|h))\s*\b\s*/gi
);
const expectedDurationRegex = getExpectedDurationRegex();
const match = expectedDurationRegex.exec(text);
if (match === null) {
return null;
Expand All @@ -47,9 +71,7 @@ export function extractStartAt(
text: string
): { value: Date; match: RegExpExecArray } | null {
// TODO: need to fix this local scope problem with the regexs somehow
const startAtRegex = new RegExp(
/\b(?:start at|at|from)\s+(\d{1,2}(?::\d{2})?\s*(?:[APap]?[Mm]?))?\b/gi
);
const startAtRegex = getStartAtRegex();
const match = startAtRegex.exec(text);
if (match === null || match[1] === undefined) {
return null;
Expand Down Expand Up @@ -83,6 +105,36 @@ export function extractStartAt(
return { value: date, match };
}

export function extractDate(
text: string
): { value: Date; match: RegExpExecArray } | null {
const dateRegex = getDateRegex();
const match = dateRegex.exec(text);
if (match === null) {
return null;
}
console.log(match);
const date = new Date();
switch (match[0]) {
case "tomorrow":
case "tmr":
case "tom":
date.setDate(date.getDate() + 1);
break;
case "today":
date.setDate(date.getDate());
break;
case "next week":
date.setDate(date.getDate() + 7);
break;
default:
const days = parseInt(match[1]);
date.setDate(date.getDate() + days);
break;
}
return { value: date, match };
}

/**
* Creates Slate ranges from a regex.
* @param regex the regex to create ranges from
Expand Down
8 changes: 6 additions & 2 deletions packages/api-client/converters.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Converter, SupernovaResponse, ISupernovaTask } from "@supernova/types";
import {
Converter,
TSupernovaResponse,
ISupernovaTask,
} from "@supernova/types";

export const supernovaResponseConverter: Converter<
Response,
Promise<SupernovaResponse>
Promise<TSupernovaResponse>
> = {
convert: async (r) => {
const json = await r.json();
Expand Down

1 comment on commit df70fbf

@vercel
Copy link

@vercel vercel bot commented on df70fbf Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.