Skip to content

Commit

Permalink
feat(daily-notes): Add daily notes to home
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaglivo committed Sep 12, 2023
1 parent 4d2ce0d commit 6876cf0
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/app/(user)/ask/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageTitle from '@/app/components/ui/page-title/page-title';
export default async function Layout({ children }: { children: React.ReactNode }) {
return (
<article>
<PageTitle text="Ask Olivo" />
<div className="mb-16"><PageTitle text="Ask Olivo" /></div>
{children}
</article>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(user)/commitments/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageTitle from '@/app/components/ui/page-title/page-title';
export default async function Layout({ children }: { children: React.ReactNode }) {
return (
<article>
<PageTitle text="Commitments" />
<div className="mb-16"><PageTitle text="Commitments" /></div>
{children}
</article>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Node } from '@tiptap/core';
import { mergeAttributes, nodeInputRule, NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';
import React from 'react';
import { TbMoodCheck } from 'react-icons/tb';

import Button from '@/app/components/ui/button/button';

type ButtonExtensionComponentProps = { node: { attrs: { label: string, icon: () => JSX.Element } } };

function ButtonComponent({ node: { attrs: { label, icon } } }: ButtonExtensionComponentProps) {
return (
<NodeViewWrapper>
<Button label={label} intent="cta" icon={icon}></Button>
</NodeViewWrapper>
);
}

export default Node.create({
name: 'button',
group: 'block',
atom: true,
parseHTML() {
return [
{
tag: 'button'
}
];
},
addAttributes() {
return {
label: {
default: null
},
icon: {
default: null
}
};
},
renderHTML({ HTMLAttributes }) {
return ['button', mergeAttributes(HTMLAttributes)];
},
addNodeView() {
return ReactNodeViewRenderer(ButtonComponent);
},
addInputRules() {
return [nodeInputRule({
find: new RegExp('^action-mood$'),
type: this.type,
getAttributes: {
label: 'How are you feeling today?',
icon: () => <TbMoodCheck />
}
})];
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Context({ tags, notes, selectedTagsFilter, selectedOpera
pathname: '/workspace',
query: buildQuery(tag)
}}
className={`cursor-pointer rounded border border-neutral-800 bg-neutral-950 px-2 ${isSelected(tag) ? ' border-red-400 ' : ''}}`}
className={`cursor-pointer rounded border border-neutral-800 bg-neutral-950 px-2 ${isSelected(tag) ? ' border-red-400 ' : ''}`}
key={tag}
>
{tag}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export default async function Workspace({ searchParams }: { searchParams: { sele
const notes = await getNotesByTags(tagFilter || [], searchParams.operator);

return (
<div className="grid h-full max-h-full grid-cols-2 gap-4 pr-32">
<>
<Section>
<div className="mb-5 text-xl">Daily Notes</div>
<div className="mb-5 text-xl">Daily Note</div>
<DailyNoteEditor note={note} tags={tagLabels}></DailyNoteEditor>
</Section>

<Section>
<div className="mb-5 text-xl">Context</div>
<Context selectedOperator={searchParams.operator} selectedTagsFilter={tagFilter} tags={tagLabels} notes={notes}></Context>
</Section>
</div>
</>
);
}
2 changes: 1 addition & 1 deletion src/app/(user)/feedback/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageTitle from '@/app/components/ui/page-title/page-title';
export default async function Layout({ children }: { children: React.ReactNode }) {
return (
<section>
<PageTitle text="Feedback" />
<div className="mb-16"><PageTitle text="Feedback" /></div>
{children}
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(user)/moods/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageTitle from '@/app/components/ui/page-title/page-title';
export default async function Layout({ children }: { children: React.ReactNode }) {
return (
<article>
<PageTitle text="Your mood" />
<div className="mb-16"><PageTitle text="Your mood" /></div>
{children}
</article>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(user)/network/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageTitle from '@/app/components/ui/page-title/page-title';
export default async function NetworkLayout({ children }: { children: React.ReactNode }) {
return (
<article>
<PageTitle text="Your network" />
<div className="mb-16"><PageTitle text="Your network" /></div>
{children}
</article>
);
Expand Down
43 changes: 10 additions & 33 deletions src/app/(user)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
import { CommitmentStatus } from '@prisma/client';

import { getServerSession } from '@/lib/auth/session';
import { getCommitments } from '@/lib/commitments/get';
import { getTodaysMood } from '@/lib/moods/get';
import { getFirstName } from '@/lib/name/name';
import { forceCast } from '@/lib/types/type-caster';
import { FilterOption } from '@/lib/notes/get-notes-by-tags';

import PageTitle from '../components/ui/page-title/page-title';
import CommitmentsList from './commitments/components/list/commitments-list';
import { ClientCommitment, ServerCommitment } from './commitments/types';
import Workspace from './components/workspace/workspace';
import MoodSelector from './moods/components/mood-selector';

const statusWeight = {
[CommitmentStatus.InProgress]: 1,
[CommitmentStatus.NotStartedYet]: 2,
[CommitmentStatus.Done]: 3,
[CommitmentStatus.Abandoned]: 4
};

export default async function Home() {
export default async function Home({ searchParams }: { searchParams: { selectedTagsFilter?: string, operator?: FilterOption } }) {
const { user } = await getServerSession();
const firstName = getFirstName(user.name);

const todaysMood = await getTodaysMood(user.id);
const commitments = await getCommitments({
userId: user.id,
filters: { status: 'not-abandoned', doneBy: 'today' },
order: { createdAt: 'desc' }
});

const sortedCommitments = commitments.sort((first, second) => statusWeight[first.status] - statusWeight[second.status]);
const notDoneCommitmentsCount = commitments.filter((commitment) => commitment.status === CommitmentStatus.InProgress || commitment.status === CommitmentStatus.NotStartedYet).length;

return (
<article>
<PageTitle text={`👋 Hey, ${firstName}`} />
<div className="mb-10"><MoodSelector todaysMood={todaysMood} /></div>
<div className="max-w-2xl rounded-lg p-4 pt-6 outline outline-1 outline-neutral-800">
<div className="mb-8 flex items-center justify-between text-xl leading-none">
<h2 className="text-white">
{notDoneCommitmentsCount > 0 ? 'Commitments for today' : 'All done for today 🎉'}
</h2>
<div className="text-neutral-300">{notDoneCommitmentsCount} left</div>
</div>
<CommitmentsList commitments={forceCast<ServerCommitment[], ClientCommitment[]>(sortedCommitments)} />
<article className="flex h-full max-h-full flex-col">
<div className="flex items-center gap-10 py-4">
<PageTitle text={`👋 Hey, ${firstName}`} />
<MoodSelector todaysMood={todaysMood} />
</div>
<div className="grid min-h-0 grid-cols-2 gap-4 pr-16">
<Workspace searchParams={searchParams}></Workspace>
</div>
</article>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/ui/page-title/page-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ type Props = { text: string };

export default function PageTitle({ text }: Props) {
return (
<h1 className="mb-16 text-4xl">{text}</h1>
<h1 className="text-4xl">{text}</h1>
);
}
6 changes: 0 additions & 6 deletions src/app/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export const links: NavigationLink[] = [
title: 'Home',
icon: <AiFillHome size={18} />
},
{
id: 'workspace',
path: '/workspace',
title: 'Workspace',
icon: <AiFillHome size={18} />
},
{
id: 'pending',
path: '/pending',
Expand Down

0 comments on commit 6876cf0

Please sign in to comment.