Skip to content

Commit

Permalink
add browse filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
slikts committed Dec 23, 2024
1 parent f4672b0 commit 39ac444
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions apps/api/src/trpc/routers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export const mediaRouter = router({
mimeType: true,
fileSize: true,
checksum: true,
createdAt: true,
createdBy: {
select: {
name: true,
email: true,
},
},
mediaVersions: {
select: {
processedMedia: {
Expand Down
42 changes: 41 additions & 1 deletion apps/web/src/features/browse/browse-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from '@mui/material';
import { Box, Dialog } from '@mui/material';
import {
DataGrid,
GridFilterModel,
Expand All @@ -11,6 +11,7 @@ import { trpc } from '../../trpc';

const MEDIA_URL = process.env.MEDIA_URL;
export const BrowsePage = () => {
const [selectedImage, setSelectedImage] = useState<string | null>(null);
const [paginationModel, setPaginationModel] = useState({
pageSize: 10,
page: 0,
Expand Down Expand Up @@ -48,7 +49,9 @@ export const BrowsePage = () => {
height: 'auto',
maxHeight: '60px',
objectFit: 'contain',
cursor: 'pointer',
}}
onClick={() => setSelectedImage(params.value)}
/>
),
},
Expand All @@ -72,6 +75,24 @@ export const BrowsePage = () => {
return tags.join(', ');
},
},

{
field: 'createdAt',
headerName: 'Created At',
width: 180,

valueFormatter: (date: string) => new Date(date).toLocaleString(),
type: 'dateTime',
},

{
field: 'createdBy',
headerName: 'Created By',
width: 150,

valueGetter: (params: GridRenderCellParams) =>
params.value?.name || params.value?.email,
},
];

const rows =
Expand All @@ -83,6 +104,8 @@ export const BrowsePage = () => {
fileSize: item.fileSize,
checksum: item.checksum,
tags: item.mediaVersions[0]?.mediaTags?.map((mt) => mt.tag.value),
createdAt: item.createdAt,
createdBy: item.createdBy,
})) || [];

return (
Expand All @@ -104,6 +127,23 @@ export const BrowsePage = () => {
onFilterModelChange={setFilterModel}
/>
</Box>

<Dialog
open={!!selectedImage}
onClose={() => setSelectedImage(null)}
maxWidth="lg"
>
{selectedImage && (
<img
src={`${MEDIA_URL}/${selectedImage}`}
alt="Full size preview"
style={{
maxWidth: '100%',
maxHeight: '90vh',
}}
/>
)}
</Dialog>
</Page>
);
};

0 comments on commit 39ac444

Please sign in to comment.