Skip to content

Commit

Permalink
Refactor department and record pages
Browse files Browse the repository at this point in the history
  • Loading branch information
brandnholl committed Aug 4, 2024
1 parent 9bd733c commit a739ce2
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 134 deletions.
11 changes: 0 additions & 11 deletions apps/web/app/(app)/[departmentid]/[locationid]/page.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
} from 'lucide-react';

export default async function Campus({
params: { departmentid },
params: { departmentslug },
}: {
params: { departmentid: string };
params: { departmentslug: string };
}) {
const department = await getDepartment(departmentid);
const department = await getDepartment(departmentslug);

if (!department) {
return <div>Campus not found</div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { SinglePointMap } from '@/components/maps/single-point';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { getRecord, getCoordinate } from '@/lib/record';
import { getIdFromSlug } from '../../../../../lib/utils';

export default async function Record({
params: { campusid, locationid, recordid },
params: { departmentslug, recordid },
}: {
params: { campusid: string; locationid: string; recordid: string };
params: { departmentslug: string; recordid: string };
}) {
const record = await getRecord(campusid, locationid, recordid);
const record = await getRecord(getIdFromSlug(departmentslug), recordid);
if (!record) {
return <div>Record not found</div>;
}
Expand Down
84 changes: 42 additions & 42 deletions apps/web/components/ui/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
"use client"
'use client';

import * as React from "react"
import * as TabsPrimitive from "@radix-ui/react-tabs"
import * as React from 'react';
import * as TabsPrimitive from '@radix-ui/react-tabs';

import { cn } from "@/lib/utils"
import { cn } from '@/lib/utils';

const Tabs = TabsPrimitive.Root
const Tabs = TabsPrimitive.Root;

const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn(
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
className
)}
{...props}
/>
))
TabsList.displayName = TabsPrimitive.List.displayName
<TabsPrimitive.List
ref={ref}
className={cn(
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground',
className
)}
{...props}
/>
));
TabsList.displayName = TabsPrimitive.List.displayName;

const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
className
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
<TabsPrimitive.Trigger
ref={ref}
className={cn(
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
className
)}
{...props}
/>
));
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;

const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn(
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
className
)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName
<TabsPrimitive.Content
ref={ref}
className={cn(
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
className
)}
{...props}
/>
));
TabsContent.displayName = TabsPrimitive.Content.displayName;

export { Tabs, TabsList, TabsTrigger, TabsContent }
export { Tabs, TabsList, TabsTrigger, TabsContent };
10 changes: 2 additions & 8 deletions apps/web/lib/record.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { supabase } from './supabase/client';

export async function getRecord(
campusid: string,
locationid: string,
recordid: string
) {
export async function getRecord(departmentid: number , recordid: string) {
const { data: record } = await supabase
.from('records')
.select()
.match({ campus: campusid })
.match({ parsed_location: locationid })
.match({ record_id: recordid })
.match({ department_id: departmentid, record_id: recordid })
.single();
if (!record) {
return null;
Expand Down
10 changes: 10 additions & 0 deletions apps/web/lib/supabase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type Database = {
parsed_location: string | null;
parsed_time_occurred: string | null;
record_id: string;
resource_id: string | null;
summary: string | null;
time_occurred: string | null;
};
Expand All @@ -104,6 +105,7 @@ export type Database = {
parsed_location?: string | null;
parsed_time_occurred?: string | null;
record_id: string;
resource_id?: string | null;
summary?: string | null;
time_occurred?: string | null;
};
Expand All @@ -120,6 +122,7 @@ export type Database = {
parsed_location?: string | null;
parsed_time_occurred?: string | null;
record_id?: string;
resource_id?: string | null;
summary?: string | null;
time_occurred?: string | null;
};
Expand All @@ -131,6 +134,13 @@ export type Database = {
referencedRelation: 'departments';
referencedColumns: ['department_id'];
},
{
foreignKeyName: 'records_resource_id_fkey';
columns: ['resource_id'];
isOneToOne: false;
referencedRelation: 'resources';
referencedColumns: ['resource_id'];
},
];
};
resources: {
Expand Down
142 changes: 75 additions & 67 deletions apps/web/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,100 @@ export function cn(...inputs: ClassValue[]) {
export function formatDate(dateString: any) {
const date = new Date(dateString);
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
const daySuffixes = [
"th",
"st",
"nd",
"rd",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"st",
"nd",
"rd",
"th",
"th",
"th",
"th",
"th",
"th",
"th",
"st",
'th',
'st',
'nd',
'rd',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'st',
'nd',
'rd',
'th',
'th',
'th',
'th',
'th',
'th',
'th',
'st',
];

const day = date.getDate();
const monthIndex = date.getMonth();

return `${monthNames[monthIndex]} ${day}${daySuffixes[day - 1]}`;
}
export function getDayOfWeek(date: string): string {
}

export function getDayOfWeek(date: string): string {
const weekDays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];
const dt = new Date(date);
return weekDays[dt.getDay()];
}
export function getTimeSince(date: string): string {
}

export function getTimeSince(date: string): string {
const msPerMinute = 60 * 1000;
const msPerHour = msPerMinute * 60;
const msPerDay = msPerHour * 24;

const current = new Date();
const previous = new Date(date);

if (previous > current) {
return "Error, date is in the future";
return 'Error, date is in the future';
}

const elapsed = current.getTime() - previous.getTime();

if (elapsed < msPerHour) {
return Math.round(elapsed / msPerMinute) + " minutes ago";
return Math.round(elapsed / msPerMinute) + ' minutes ago';
} else if (elapsed < msPerDay) {
return Math.round(elapsed / msPerHour) + " hours ago";
return Math.round(elapsed / msPerHour) + ' hours ago';
} else {
return Math.round(elapsed / msPerDay) + " days ago";
return Math.round(elapsed / msPerDay) + ' days ago';
}
}
}

const slugToIdMap: { [key: string]: number } = {
ucsd: 1,
};

export function getIdFromSlug(slug: string): number {
return slugToIdMap[slug];
}

0 comments on commit a739ce2

Please sign in to comment.