Skip to content

Commit

Permalink
Reflect: add timestamp format preference (raycast#7456)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Jul 13, 2023
1 parent f7b58e7 commit 54271b8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions extensions/reflect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Reflect Changelog

## [Time format] - 2023-07-10

### Added

- Support 24-hour time format

## [OAuth & Append] - 2023-05-15

### Added
Expand Down
18 changes: 17 additions & 1 deletion extensions/reflect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"author": "ryon",
"contributors": [
"joshknowles",
"tylerwince"
"tylerwince",
"ocavue"
],
"categories": [
"Applications",
Expand Down Expand Up @@ -58,6 +59,21 @@
"description": "Prepend a timestamp to your note",
"type": "checkbox",
"required": false
},
{
"name": "timestampFormat",
"title": "Timestamp Format",
"description": "The format of prepended timestamp",
"type": "dropdown",
"data": [{
"title": "12 hour",
"value": "12"
},{
"title": "24 hour",
"value": "24"
}],
"default": "12",
"required": false
}
],
"arguments": [
Expand Down
14 changes: 13 additions & 1 deletion extensions/reflect/src/append.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface FormValues {
prependTimestamp: boolean;
parentList: string;
graphId: string;
timestampFormat?: string;
}

export default function Command() {
Expand All @@ -23,7 +24,10 @@ export default function Command() {

try {
const authorizationToken = await authorize();
const text = prependTimestampIfSelected(values.note, values);
const text = prependTimestampIfSelected(values.note, {
prependTimestamp: values.prependTimestamp,
timestampFormat: values.timestampFormat as "12" | "24" | undefined,
});

await appendToDailyNote(authorizationToken, values.graphId, text, values.parentList);
await LocalStorage.setItem("graphId", values.graphId);
Expand Down Expand Up @@ -62,6 +66,8 @@ export default function Command() {
fetchData();
}, []);

const showTimestampFormat: boolean = itemProps.prependTimestamp.value ?? false;

return (
<Form
actions={
Expand All @@ -72,6 +78,12 @@ export default function Command() {
>
<Form.TextArea {...itemProps.note} title="Note" />
<Form.Checkbox {...itemProps.prependTimestamp} label="Prepend Timestamp" storeValue={true} />
{showTimestampFormat ? (
<Form.Dropdown {...itemProps.timestampFormat} storeValue={true}>
<Form.Dropdown.Item value="12" title="12 hour" />
<Form.Dropdown.Item value="24" title="24 hour" />
</Form.Dropdown>
) : null}
<Form.TextField
{...itemProps.parentList}
title="Parent List (Optional)"
Expand Down
3 changes: 2 additions & 1 deletion extensions/reflect/src/helpers/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export function getTodaysDateAsISOString() {

interface Preferences {
prependTimestamp?: boolean;
timestampFormat?: "12" | "24";
}

export function prependTimestampIfSelected(text: string, preferences: Preferences) {
if (preferences.prependTimestamp) {
const timestamp = format(new Date(), "h:maaa");
const timestamp = format(new Date(), preferences.timestampFormat === "24" ? "HH:mm" : "h:mmaaa");
text = `${timestamp} ${text}`;
}
return text;
Expand Down

0 comments on commit 54271b8

Please sign in to comment.