Skip to content

Commit

Permalink
tidying and making mobile friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
rohannair committed Aug 3, 2024
1 parent 1e88e3a commit 446d933
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 104 deletions.
5 changes: 3 additions & 2 deletions apps/ui/src/app/(app)/_components/ColorToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client'

import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { MoonIcon, SunIcon } from 'lucide-react'
import { useTheme } from 'next-themes'
import { match } from 'ts-pattern'

export function ColorToggle() {
export function ColorToggle({ className }: { className?: string }) {
const { setTheme, resolvedTheme } = useTheme()

const { icon, onClick } = match(resolvedTheme)
Expand All @@ -27,7 +28,7 @@ export function ColorToggle() {
variant="ghost"
size="sm"
onClick={onClick}
className="w-full text-xs"
className={cn('w-full text-xs', className)}
>
{icon}
</Button>
Expand Down
9 changes: 5 additions & 4 deletions apps/ui/src/app/(app)/_components/LogoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import {
import { cn } from '@/lib/utils'
import { LogOut } from 'lucide-react'

export const LogoutButton = () => {
export const LogoutButton = ({ className }: { className: string }) => {
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
onClick={() => {}}
className={
'flex px-3 py-4 items-center justify-center hover:bg-transparent'
}
className={cn(
'flex px-3 py-4 items-center justify-center hover:bg-transparent',
className,
)}
>
<LogOut className="size-[1.2rem]" />
</Button>
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/app/(app)/bookmarks/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default async function BookmarkLayout({
const { linksCount, categoriesCount, tagsCount } = await getLinksMetadata()

return (
<div className="grid grid-cols-12 min-h-screen">
<div className="md:grid md:grid-cols-12 min-h-screen">
<div className="flex flex-col col-span-2 border-r bg-secondary border-border p-4 relative">
<div className="sticky top-4">
<Heading>Links</Heading>
Expand Down
24 changes: 17 additions & 7 deletions apps/ui/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ import Link from 'next/link'
import { NavLink } from './_components/NavLink'
import { ColorToggle } from './_components/ColorToggle'
import { LogoutButton } from './_components/LogoutButton'
import { cn } from '@/lib/utils'

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex flex-row h-screen">
<div className="flex flex-col w-full md:w-screen md:flex-row md:h-screen">
<nav className="min-h-full relative">
<div className="flex flex-col fixed inset-y-0 left-0 z-50 w-16 overflow-y-auto pb-4 h-full">
<Link href="/" className="flex px-3 py-4 items-center justify-center">
<div
className={cn(
'flex flex-row w-full',
'z-50 overflow-y-auto md:pb-4 md:h-full',
'md:flex-col md:fixed md:inset-y-0 md:left-0 md:w-16',
)}
>
<Link
href="/"
className="flex w-16 h-20 p-2 md:px-3 md:py-4 items-center justify-center"
>
<Logomark />
</Link>
<NavLink href="/bookmarks" description="Bookmarks" icon="bookmark" />
<NavLink href="/folders" description="Folders" icon="folder" />
<div className="mt-auto flex flex-col gap-2">
<ColorToggle />
<LogoutButton />
<div className="flex flex-row pr-2 md:pr-0 md:gap-2 ml-auto md:mt-auto md:flex-col ">
<ColorToggle className="h-full px-2" />
<LogoutButton className="h-full px-2" />
</div>
</div>
</nav>
<div className="flex flex-col flex-grow pl-16">{children}</div>
<div className="flex flex-col flex-grow md:pl-16">{children}</div>
</div>
)
}
6 changes: 3 additions & 3 deletions apps/ui/src/components/LinkDisplay/LinkDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ interface LinkDisplayProps {

export function LinkDisplay({ summary, cleaned }: LinkDisplayProps) {
return (
<section className="flex flex-col relative lg:grid lg:grid-cols-12 ">
<section className="flex flex-col relative md:grid md:grid-cols-12">
<Markdown>{cleaned}</Markdown>

<div className="order-first flex flex-col gap-4 relative lg:order-last lg:col-span-4 lg:px-2 lg:pt-6">
<div className="lg:pr-4">
<div className="order-first flex flex-col gap-4 mb-4 relative md:order-last md:col-span-4 md:px-2 md:pt-6 md:mb-0">
<div className="md:pr-4">
{summary ? <Summary summary={summary} /> : <Skeleton />}
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/ui/src/components/LinkList/LinkDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export function LinkDrawer({ id, close }: LinkDrawerProps) {

return link ? (
<>
<DrawerHeader>
<DrawerHeader className="border-b border-border shadow-sm">
<DrawerTitle>
<div className="flex lg:flex-row">
<h3 className="text-left">{link?.title}</h3>
<div className="ml-auto flex flex-row gap-2">
<h3 className="text-left text-2xl md:text-lg">{link?.title}</h3>
<div className="ml-auto flex flex-row gap-2 ">
<Button size="icon" variant="outline" asChild className="size-7">
<Link href={`/bookmarks/${link.id}`}>
<Expand className="h-4 w-4" />
Expand Down Expand Up @@ -90,7 +90,7 @@ export function LinkDrawer({ id, close }: LinkDrawerProps) {
)}
</DrawerDescription>
</DrawerHeader>
<div className="py-4 px-10 max-h-96 overflow-y-scroll">
<div className="p-4 max-h-[67vh] overflow-y-scroll">
<LinkDisplay summary={link.summary} cleaned={link.cleaned} />
</div>
<DrawerFooter>
Expand Down
22 changes: 13 additions & 9 deletions apps/ui/src/components/LinkList/LinkItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useState } from 'react'
interface LinkItemsProps {
links: {
id: string
href: string
prefetch?: boolean
title: string
url: string
Expand Down Expand Up @@ -44,7 +43,9 @@ export function LinkItems({ links }: LinkItemsProps) {
<DrawerTrigger
key={link.id}
className={cn(
'grid grid-cols-12 w-full text-left gap-5 p-2 hover:shadow-md transition-shadow rounded-lg',
'flex flex-col gap-2 cursor-pointer w-full p-2',
'md:grid md:grid-cols-12 w-full text-left md:gap-5 md:p-4',
'hover:shadow-md transition-shadow rounded-lg',
'dark:hover:bg-primary/2- dark:transition-colors',
'ease-in-out duration-75 group',
)}
Expand All @@ -62,27 +63,27 @@ export function LinkItems({ links }: LinkItemsProps) {
)
}}
>
<section className="col-span-3 flex rounded-md overflow-hidden shadow-md">
<section className="w-full flex rounded-md shadow-sm md:col-span-3 md:overflow-hidden">
<AspectRatio ratio={16 / 9} className="w-full">
<Image
src={
link.imageUrl ??
'https://placehold.co/250x140/png?text=No+Image'
'https://placehold.co/750x420/png?text=No+Image'
}
fill
className="object-cover"
alt={link.title ?? link.url}
/>
</AspectRatio>
</section>
<section className="col-span-8">
<div className="flex flex-row gap-1 items-baseline">
<h3 className="font-semibold text-lg truncate">
<section className="md:col-span-8 flex flex-col">
<div className="flex md:flex-row gap-1 items-baseline">
<h3 className="font-semibold text-2xl md:text-lg truncate text-wrap">
{link.title ?? link.url}
</h3>
<StatusIcon status={link.status} />
<StatusIcon className="" status={link.status} />
</div>
<div className="text-sm text-muted-foreground">
<div className="text-sm text-muted-foreground text-wrap truncate">
{link.title ? link.url : null}
</div>
<div className="text-sm text-foreground">
Expand All @@ -105,6 +106,9 @@ export function LinkItems({ links }: LinkItemsProps) {
direction: direction || 'desc',
search: search || '',
}).toString()}`,
{
scroll: false,
},
)
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/LinkList/LinkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export async function LinkList({ links, pagination }: LinkListProps) {
Search
</Button>
</div>
<div className="grid gap-4">
<div className="md:grid md:gap-4">
<div className="space-y-4">
<LinkItems links={links} />
</div>
</div>
</main>
{/* <LinkDrawer /> */}

<aside className="flex my-4 mx-auto w-full justify-center">
<Pagination>
<PaginationContent>
Expand Down
38 changes: 18 additions & 20 deletions apps/ui/src/components/StatusBadge/StatusBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import React from 'react'
import { Badge } from '@/components/ui/badge'
import { CircleCheckBig, CircleGauge, CircleX } from 'lucide-react'
import { match } from 'ts-pattern'

type BadgeColor = 'secondary' | 'destructive' | 'default'
type BadgeColor = 'secondary' | 'destructive' | 'default' | 'outline'
type StatusType = 'completed' | 'processing' | 'error'

export const StatusBadge = ({
status,
}: {
status: 'completed' | 'processing' | 'error'
}) => {
const { variant, icon } = match<string>(status)
export const StatusBadge = ({ status }: { status: StatusType }) => {
const statusConfig = match(status)
.with('error', () => ({
variant: 'destructive',
icon: <CircleX className="w-4 h-4" />,
variant: 'destructive' as BadgeColor,
Icon: CircleX,
text: 'error',
}))
.with('completed', () => ({
variant: 'default',
icon: <CircleCheckBig className="w-4 h-4" />,
variant: 'default' as BadgeColor,
Icon: CircleCheckBig,
text: 'completed',
}))
.otherwise(() => ({
variant: 'outline',
icon: <CircleGauge className="w-4 h-4" />,
})) as {
variant: BadgeColor
icon: JSX.Element | undefined
}
variant: 'outline' as BadgeColor,
Icon: CircleGauge,
text: 'processing',
}))

return (
<Badge
variant={variant}
variant={statusConfig.variant}
className="text-xs flex-grow-0 opacity-75 inline-flex gap-1"
>
{icon}
{status}
<statusConfig.Icon className="w-4 h-4" />
{statusConfig.text}
</Badge>
)
}
96 changes: 44 additions & 52 deletions apps/ui/src/components/StatusIcon/StatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,56 @@
import React from 'react'
import { Tooltip, TooltipTrigger } from '@/components/ui/tooltip'
import { cn } from '@/lib/utils'
import { TooltipContent } from '@radix-ui/react-tooltip'
import {
CircleCheckBigIcon,
CircleCheckIcon,
CircleDashedIcon,
CircleDotDashedIcon,
CircleGaugeIcon,
CircleXIcon,
} from 'lucide-react'
import { match } from 'ts-pattern'

export type LinkStatus = 'submitted' | 'processing' | 'completed' | 'error'
export function StatusIcon({ status }: { status: LinkStatus }) {
return match(status)
.with('submitted', () => (
<span className="text-yellow-500">
<Tooltip>
<TooltipTrigger>
<CircleDashedIcon className="size-3" />
</TooltipTrigger>
<TooltipContent>
<div className="text-xs mb-1">Submitted</div>
</TooltipContent>
</Tooltip>
</span>
))
.with('processing', () => (
<span className="text-yellow-500">
<Tooltip>
<TooltipTrigger>
<CircleGaugeIcon className="size-3" />
</TooltipTrigger>
<TooltipContent>
<div className="text-xs mb-1">Processing</div>
</TooltipContent>
</Tooltip>
</span>
))
.with('completed', () => (
<span className="text-green-500">
<Tooltip>
<TooltipTrigger>
<CircleCheckBigIcon className="size-3" />
</TooltipTrigger>
<TooltipContent>
<div className="text-xs mb-1">Completed</div>
</TooltipContent>
</Tooltip>
</span>
))
.otherwise(() => (
<span className="text-red-500">
<Tooltip>
<TooltipTrigger>
<CircleXIcon className="size-3" />
</TooltipTrigger>
<TooltipContent>
<div className="text-xs mb-1">Error</div>
</TooltipContent>
</Tooltip>
</span>
))

export function StatusIcon({
status,
className,
}: {
status: LinkStatus
className?: string
}) {
const statusConfig = match(status)
.with('submitted', () => ({
color: 'text-yellow-500',
Icon: CircleDashedIcon,
tooltipText: 'Submitted',
}))
.with('processing', () => ({
color: 'text-yellow-500',
Icon: CircleGaugeIcon,
tooltipText: 'Processing',
}))
.with('completed', () => ({
color: 'text-green-500',
Icon: CircleCheckBigIcon,
tooltipText: 'Completed',
}))
.otherwise(() => ({
color: 'text-red-500',
Icon: CircleXIcon,
tooltipText: 'Error',
}))

return (
<span className={cn(statusConfig.color, className)}>
<Tooltip>
<TooltipTrigger>
<statusConfig.Icon className="size-3" />
</TooltipTrigger>
<TooltipContent>
<div className="text-xs mb-1">{statusConfig.tooltipText}</div>
</TooltipContent>
</Tooltip>
</span>
)
}

0 comments on commit 446d933

Please sign in to comment.