Skip to content

Commit

Permalink
add reminders to mentionable notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonrovirosa committed Sep 7, 2023
1 parent 1de10bf commit 348377d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs lts-gallium
nodejs 16.14.2
yarn 1.22.19
1 change: 1 addition & 0 deletions src/components/Note/Note.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const NoteWithMentions = () => {
onChange={action('onChange')}
onDelete={action('onDelete')}
onEdit={action('onEdit')}
onSetReminder={action('onSetReminder')}
onSave={action('onSave')}
onUndelete={action('onUndelete')}
rows={number('rows', Note.defaultProps.rows)}
Expand Down
57 changes: 55 additions & 2 deletions src/components/Note/NoteHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import classnames from 'classnames';
import fecha from 'fecha';
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import Badge from '../Badge/Badge';
import Button from '../Button/Button';
import ButtonDropdown from '../Button/ButtonDropdown'
import DropdownItem from '../Dropdown/DropdownItem';
import DropdownMenu from '../Dropdown/DropdownMenu';
import DropdownToggle from '../Dropdown/DropdownToggle';
import CardHeader from '../Card/CardHeader';
import CardTitle from '../Card/CardTitle';
import { Note } from './Note.types';
Expand All @@ -20,15 +24,17 @@ type NoteHeaderProps = {
showTimezone?: boolean;
onDelete?: (note: Omit<Note, 'text'>) => void;
onEdit?: (note: Omit<Note, 'text'>) => void;
onSetReminder?: (note: Omit<Note, 'text'>, time: number) => void;
};

const defaultProps = {
dateFormat: 'ddd MMM DD YYYY HH:mm:ss',
};

const NoteHeader: FC<NoteHeaderProps> = ({ dateFormat = defaultProps.dateFormat, ...props }) => {
const { note, onDelete, onEdit, showTimezone } = props;
const { note, onDelete, onEdit, showTimezone, onSetReminder } = props;
const { date, edited, from, title } = note;
const [isOpen, setIsOpen] = useState(false);

const headerClassNames = classnames(
'd-flex',
Expand Down Expand Up @@ -91,6 +97,53 @@ const NoteHeader: FC<NoteHeaderProps> = ({ dateFormat = defaultProps.dateFormat,
Delete
</Button>
) : null}
{ onSetReminder ? (
<div className="ms-3">
<ButtonDropdown isOpen={isOpen} toggle={() => setIsOpen(!isOpen)}>
<DropdownToggle caret>Remind Me</DropdownToggle>
<DropdownMenu>
<DropdownItem
onClick={() => onSetReminder(
note,
new Date().setMinutes(
new Date().getMinutes() + 20
)
)}
>
In 20 minutes</DropdownItem>
<DropdownItem
onClick={() => onSetReminder(
note,
new Date().setMinutes(
new Date().getMinutes() + 60
)
)}
>
In 1 hour</DropdownItem>
<DropdownItem
onClick={() => onSetReminder(
note,
new Date().setMinutes(
new Date().getMinutes() + 1440
)
)}
>
Tomorrow
</DropdownItem>
<DropdownItem
onClick={() => onSetReminder(
note,
new Date().setMinutes(
new Date().getMinutes() + 10080
)
)}
>
Next Week
</DropdownItem>
</DropdownMenu>
</ButtonDropdown>
</div>
) : null}
</div>
</CardHeader>
) : (
Expand Down
3 changes: 3 additions & 0 deletions src/components/Note/NoteMentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type NoteMentionsProps = {
onDelete?: (note: Omit<NoteType, 'text'>) => void;
onEdit?: (note: Omit<NoteType, 'text'>) => void;
onSave?: (note: NoteType) => void;
onSetReminder?: (note: Omit<NoteType, 'text'>, time: number) => void;
onUndelete?: (note: NoteType) => void;
rows?: number;
saving?: boolean;
Expand Down Expand Up @@ -59,6 +60,7 @@ const NoteMentions: FC<NoteMentionsProps> = ({
onDelete,
onEdit,
onSave,
onSetReminder,
onUndelete,
}) => {
const { deleted, editing, text } = note;
Expand Down Expand Up @@ -106,6 +108,7 @@ const NoteMentions: FC<NoteMentionsProps> = ({
showTimezone={showTimezone}
onDelete={onDelete}
onEdit={onEdit}
onSetReminder={onSetReminder}
/>
<CardBody>
<CardText style={{ whiteSpace: 'pre-wrap' }}>
Expand Down

0 comments on commit 348377d

Please sign in to comment.