Skip to content

Commit

Permalink
add event date filter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
xvvvyz committed Mar 19, 2024
1 parent 30d93cd commit 28db26a
Show file tree
Hide file tree
Showing 74 changed files with 358 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import formatTitle from '@/_utilities/format-title';

interface PageProps {
params: { subjectId: string };
searchParams: { to?: string };
searchParams: { from?: string; limit?: string; to?: string };
}

export const generateMetadata = async ({
Expand All @@ -14,9 +14,11 @@ export const generateMetadata = async ({
return { title: formatTitle([subject?.name, 'Events']) };
};

const Page = async ({
const Page = ({
params: { subjectId },
searchParams: { to },
}: PageProps) => <SubjectEventsPage eventsTo={to} subjectId={subjectId} />;
searchParams: { from, limit, to },
}: PageProps) => (
<SubjectEventsPage from={from} limit={limit} subjectId={subjectId} to={to} />
);

export default Page;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import listEvents from '@/_actions/list-events';
import Numbers from '@/_constants/enum-numbers';
import listEvents from '@/_queries/list-events';
import formatTabularEventsCsvResponse from '@/_utilities/format-tabular-events-csv-response';

interface GetContext {
Expand All @@ -9,9 +9,8 @@ interface GetContext {
}

export const GET = async (_: Request, ctx: GetContext) => {
const { data } = await listEvents({
const { data } = await listEvents(ctx.params.subjectId, {
from: 0,
subjectId: ctx.params.subjectId,
to: Numbers.FourByteSignedIntMax - 1,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import listEvents from '@/_actions/list-events';
import Numbers from '@/_constants/enum-numbers';
import listEvents from '@/_queries/list-events';
import formatTabularEventsJsonResponse from '@/_utilities/format-tabular-events-json-response';

interface GetContext {
Expand All @@ -9,9 +9,8 @@ interface GetContext {
}

export const GET = async (_: Request, ctx: GetContext) => {
const { data } = await listEvents({
const { data } = await listEvents(ctx.params.subjectId, {
from: 0,
subjectId: ctx.params.subjectId,
to: Numbers.FourByteSignedIntMax - 1,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import formatTitle from '@/_utilities/format-title';

interface PageProps {
params: { subjectId: string };
searchParams: { to?: string };
searchParams: { foo?: string; from?: string; limit?: string; to?: string };
}

export const generateMetadata = async ({
Expand All @@ -16,9 +16,15 @@ export const generateMetadata = async ({

const Page = async ({
params: { subjectId },
searchParams: { to },
searchParams: { from, limit, to },
}: PageProps) => (
<SubjectEventsPage eventsTo={to} isPublic subjectId={subjectId} />
<SubjectEventsPage
from={from}
limit={limit}
isPublic
subjectId={subjectId}
to={to}
/>
);

export default Page;
6 changes: 2 additions & 4 deletions app/(pages)/(public)/share/[subjectId]/events.csv/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import listEvents from '@/_actions/list-events';
import Numbers from '@/_constants/enum-numbers';
import listPublicEvents from '@/_queries/list-public-events';
import formatTabularEventsCsvResponse from '@/_utilities/format-tabular-events-csv-response';

interface GetContext {
Expand All @@ -9,10 +9,8 @@ interface GetContext {
}

export const GET = async (_: Request, ctx: GetContext) => {
const { data } = await listEvents({
const { data } = await listPublicEvents(ctx.params.subjectId, {
from: 0,
isPublic: true,
subjectId: ctx.params.subjectId,
to: Numbers.FourByteSignedIntMax - 1,
});

Expand Down
6 changes: 2 additions & 4 deletions app/(pages)/(public)/share/[subjectId]/events.json/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import listEvents from '@/_actions/list-events';
import Numbers from '@/_constants/enum-numbers';
import listPublicEvents from '@/_queries/list-public-events';
import formatTabularEventsJsonResponse from '@/_utilities/format-tabular-events-json-response';

interface GetContext {
Expand All @@ -9,10 +9,8 @@ interface GetContext {
}

export const GET = async (_: Request, ctx: GetContext) => {
const { data } = await listEvents({
const { data } = await listPublicEvents(ctx.params.subjectId, {
from: 0,
isPublic: true,
subjectId: ctx.params.subjectId,
to: Numbers.FourByteSignedIntMax - 1,
});

Expand Down
21 changes: 0 additions & 21 deletions app/_actions/list-events.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/_components/account-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import signOut from '@/_actions/sign-out';
import Avatar from '@/_components/avatar';
import Menu from '@/_components/menu';
import signOut from '@/_mutations/sign-out';
import ArrowLeftStartOnRectangleIcon from '@heroicons/react/24/outline/ArrowLeftStartOnRectangleIcon';
import Bars3Icon from '@heroicons/react/24/outline/Bars3Icon';
import Cog6ToothIcon from '@heroicons/react/24/outline/Cog6ToothIcon';
Expand Down
4 changes: 2 additions & 2 deletions app/_components/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const Calendar = ({
day_hidden: 'invisible',
day_outside: 'text-fg-4',
day_range_end:
'rounded-r-sm aria-selected:border-alpha-1 aria-selected:border-l-transparent rounded-l-none bg-alpha-2',
'rounded-r-sm aria-selected:border-alpha-1 aria-selected:border-l-transparent aria-selected:group-first:border-l-alpha-1 rounded-l-none group-first:rounded-l-sm bg-alpha-2',
day_range_middle:
'bg-alpha-2 border-y-alpha-1 aria-selected:rounded-none group-last:border-r-alpha-1 group-first:border-l-alpha-1 group-last:rounded-r-sm group-first:rounded-l-sm',
day_range_start:
'rounded-l-sm rounded-r-none aria-selected:border-alpha-1 aria-selected:border-r-transparent bg-alpha-2',
'rounded-l-sm rounded-r-none group-last:rounded-r-sm aria-selected:group-last:border-r-alpha-1 aria-selected:border-alpha-1 aria-selected:border-r-transparent bg-alpha-2',
head_cell: 'w-9 text-fg-4 font-normal',
head_row: 'flex mb-1 mt-0.5',
month: 'space-y-4',
Expand Down
2 changes: 1 addition & 1 deletion app/_components/change-password-form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import updatePassword from '@/_actions/update-password';
import Button from '@/_components/button';
import Input from '@/_components/input';
import updatePassword from '@/_mutations/update-password';
import { useFormState } from 'react-dom';

const ChangePasswordForm = () => {
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-comment-form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import addComment from '@/_actions/add-comment';
import IconButton from '@/_components/icon-button';
import RichTextarea from '@/_components/rich-textarea';
import addComment from '@/_mutations/add-comment';
import PaperAirplaneIcon from '@heroicons/react/24/outline/PaperAirplaneIcon';
import { useRef, useTransition } from 'react';
import { Controller, useForm } from 'react-hook-form';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-comment.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client';

import deleteComment from '@/_actions/delete-comment';
import Alert from '@/_components/alert';
import Avatar from '@/_components/avatar';
import DateTime from '@/_components/date-time';
import DirtyHtml from '@/_components/dirty-html';
import Menu from '@/_components/menu';
import deleteComment from '@/_mutations/delete-comment';
import { Database } from '@/_types/database';
import EllipsisVerticalIcon from '@heroicons/react/24/outline/EllipsisVerticalIcon';
import TrashIcon from '@heroicons/react/24/outline/TrashIcon';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-form.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import upsertEvent from '@/_actions/upsert-event';
import BackButton from '@/_components/back-button';
import Button from '@/_components/button';
import Checkbox from '@/_components/checkbox';
import Input from '@/_components/input';
import RichTextarea from '@/_components/rich-textarea';
import Select, { IOption } from '@/_components/select';
import InputTypes from '@/_constants/enum-input-types';
import upsertEvent from '@/_mutations/upsert-event';
import { GetEventData } from '@/_queries/get-event';
import { GetEventTypeWithInputsAndOptionsData } from '@/_queries/get-event-type-with-inputs-and-options';
import { GetSessionWithDetailsData } from '@/_queries/get-session-with-details';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-select.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import createInputOption from '@/_actions/create-input-option';
import { EventFormValues } from '@/_components/event-form';
import Select, { IOption } from '@/_components/select';
import createInputOption from '@/_mutations/create-input-option';
import { Database } from '@/_types/database';
import { InputSettingsJson } from '@/_types/input-settings-json';
import { useRouter } from 'next/navigation';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-type-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import upsertEventType from '@/_actions/upsert-event-type';
import Button from '@/_components/button';
import FormBanner from '@/_components/form-banner';
import Input from '@/_components/input';
Expand All @@ -9,6 +8,7 @@ import PageModalHeader from '@/_components/page-modal-header';
import RichTextarea from '@/_components/rich-textarea';
import Select, { IOption } from '@/_components/select';
import useCachedForm from '@/_hooks/use-cached-form';
import upsertEventType from '@/_mutations/upsert-event-type';
import { GetEventTypeWithInputsData } from '@/_queries/get-event-type-with-inputs';
import { GetInputData } from '@/_queries/get-input';
import { ListInputsBySubjectIdData } from '@/_queries/list-inputs-by-subject-id';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/event-type-link-list-item-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import deleteEventType from '@/_actions/delete-event-type';
import Alert from '@/_components/alert';
import Menu from '@/_components/menu';
import deleteEventType from '@/_mutations/delete-event-type';
import DocumentDuplicateIcon from '@heroicons/react/24/outline/DocumentDuplicateIcon';
import EllipsisVerticalIcon from '@heroicons/react/24/outline/EllipsisVerticalIcon';
import PencilIcon from '@heroicons/react/24/outline/PencilIcon';
Expand Down
26 changes: 11 additions & 15 deletions app/_components/events.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
import listEvents from '@/_actions/list-events';
import Empty from '@/_components/empty';
import TimelineEvents from '@/_components/timeline-events';
import listEvents from '@/_queries/list-events';
import listPublicEvents from '@/_queries/list-public-events';
import EventFilters from '@/_types/event-filters';
import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon';
import { User } from '@supabase/supabase-js';

interface EventsProps {
filters: EventFilters;
isPublic?: boolean;
isTeamMember: boolean;
subjectId: string;
to?: string;
user?: User;
}

const Events = async ({
filters,
isPublic,
isTeamMember,
subjectId,
to,
user,
}: EventsProps) => {
const pageSize = 25;
const toNumber = to ? Number(to) : pageSize - 1;

const { data: events } = await listEvents({
from: 0,
isPublic,
subjectId,
to: toNumber,
});
const { data: events, error } = isPublic
? await listPublicEvents(subjectId, filters)
: await listEvents(subjectId, filters);
console.log(error);

if (!events?.length) {
return (
<>
<div className="mx-4 h-16 border-l-2 border-dashed border-alpha-2" />
<Empty className="mt-4">
<InformationCircleIcon className="w-7" />
Recorded events will appear here.
No events.
</Empty>
</>
);
Expand All @@ -44,11 +41,10 @@ const Events = async ({
return (
<TimelineEvents
events={events}
filters={filters}
isPublic={isPublic}
isTeamMember={isTeamMember}
pageSize={pageSize}
subjectId={subjectId}
to={toNumber}
user={user}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion app/_components/forgot-password-form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import forgotPassword from '@/_actions/forgot-password';
import Button from '@/_components/button';
import Input from '@/_components/input';
import forgotPassword from '@/_mutations/forgot-password';
import { useFormState } from 'react-dom';

const ForgotPasswordForm = () => {
Expand Down
2 changes: 1 addition & 1 deletion app/_components/input-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import upsertInput from '@/_actions/upsert-input';
import BackButton from '@/_components/back-button';
import Button from '@/_components/button';
import Checkbox from '@/_components/checkbox';
Expand All @@ -11,6 +10,7 @@ import Select, { IOption } from '@/_components/select';
import INPUT_LABELS from '@/_constants/constant-input-labels';
import InputTypes from '@/_constants/enum-input-types';
import useCachedForm from '@/_hooks/use-cached-form';
import upsertInput from '@/_mutations/upsert-input';
import { GetInputData } from '@/_queries/get-input';
import { ListInputsBySubjectIdData } from '@/_queries/list-inputs-by-subject-id';
import { ListSubjectsByTeamIdData } from '@/_queries/list-subjects-by-team-id';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/input-list-item-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import deleteInput from '@/_actions/delete-input';
import Alert from '@/_components/alert';
import Menu from '@/_components/menu';
import deleteInput from '@/_mutations/delete-input';
import DocumentDuplicateIcon from '@heroicons/react/24/outline/DocumentDuplicateIcon';
import EllipsisVerticalIcon from '@heroicons/react/24/outline/EllipsisVerticalIcon';
import TrashIcon from '@heroicons/react/24/outline/TrashIcon';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/mission-form.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';

import upsertMission from '@/_actions/upsert-mission';
import BackButton from '@/_components/back-button';
import Button from '@/_components/button';
import Input from '@/_components/input';
import upsertMission from '@/_mutations/upsert-mission';
import { GetMissionData } from '@/_queries/get-mission';
import { useRouter } from 'next/navigation';
import { useTransition } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion app/_components/mission-link-list-item-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import deleteMission from '@/_actions/delete-mission';
import Alert from '@/_components/alert';
import Menu from '@/_components/menu';
import deleteMission from '@/_mutations/delete-mission';
import EllipsisVerticalIcon from '@heroicons/react/24/outline/EllipsisVerticalIcon';
import PencilIcon from '@heroicons/react/24/outline/PencilIcon';
import TrashIcon from '@heroicons/react/24/outline/TrashIcon';
Expand Down
4 changes: 2 additions & 2 deletions app/_components/notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import deleteNotification from '@/_actions/delete-notification';
import updateNotification from '@/_actions/update-notification';
import Avatar from '@/_components/avatar';
import Button from '@/_components/button';
import DateTime from '@/_components/date-time';
import DirtyHtml from '@/_components/dirty-html';
import Empty from '@/_components/empty';
import IconButton from '@/_components/icon-button';
import NotificationTypes from '@/_constants/enum-notification-types';
import deleteNotification from '@/_mutations/delete-notification';
import updateNotification from '@/_mutations/update-notification';
import { ListNotificationsData } from '@/_queries/list-notifications';
import { Database } from '@/_types/database';
import ArchiveBoxArrowDownIcon from '@heroicons/react/24/outline/ArchiveBoxArrowDownIcon';
Expand Down
Loading

0 comments on commit 28db26a

Please sign in to comment.