Skip to content

Commit

Permalink
implement new project view
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Dec 29, 2024
1 parent a2fc8a3 commit 0a48b30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
8 changes: 3 additions & 5 deletions components/ProjectGridItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<template>
<div
class="relative bg-white border border-gray-200 rounded-lg overflow-hidden aspect-square hover:shadow-lg transition-shadow duration-200 cursor-pointer"
class="bg-white border border-gray-200 rounded-lg overflow-hidden hover:shadow-lg transition-shadow duration-200 cursor-pointer"
>
<div class="absolute top-0 left-0 w-full aspect-video">
<div class="relative w-full aspect-square">
<img :src="imageSrc" :alt="imageAlt" class="w-full h-full object-cover" />
</div>

<div
class="absolute bottom-0 left-0 w-full bg-white bg-opacity-90 p-4 text-center text-lg font-semibold text-black max-h-[44.75%] overflow-hidden"
>
<div class="p-4 text-center text-2xl font-semibold text-black line-clamp-2">
<slot>{{ text }}</slot>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<UploadProjectCard />

<ProjectGridItem
v-for="project in data"
:key="project.id"
v-for="project in data.projects"
:key="project.slug"
:imageSrc="project.imageUrl"
:imageAlt="project.title"
:text="project.title"
:imageAlt="project.projectName"
:text="project.projectName"
/>
</div>
</div>
Expand Down
37 changes: 19 additions & 18 deletions server/api/projects.get.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { defineEventHandler } from "h3";
import { connectDB } from "~~/server/db/mongo";

export default defineEventHandler(async (_) => {
const items = [
{
id: "1",
imageUrl: "https://placehold.co/600x400",
title: "Sample Project 1",
},
{
id: "2",
imageUrl: "https://placehold.co/600x400",
title: "Sample 2",
},
{
id: "3",
imageUrl: "https://placehold.co/600x400",
title: "Sample Project 3",
},
];
const db = await connectDB();

return items;
const projects = await db
.collection("projects_v2")
.find()
.project({ slug: 1, projectName: 1, _id: 0 })
.toArray();

const response = projects.map((project) => {
return {
slug: project.slug,
projectName: project.projectName,
imageUrl: `/api/project/${project.slug}/preview`,
};
});

return {
projects: response,
};
});
8 changes: 4 additions & 4 deletions server/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineEventHandler(async (event) => {
const slug = standardSlugify(projectName);

const imageField = fields.find((field) => field.name === "image");
const imageBase64 = getImageAsBase64(imageField);
const imageBuffer = getImageBuffer(imageField);

const dxfFileFields = fields.filter((field) => field.name === "dxf");
const dxfStrings = getDxfStringArray(dxfFileFields);
Expand All @@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => {
await db.collection("projects_v2").insertOne({
slug: slug,
projectName: projectName,
image: imageBase64,
image: imageBuffer,
dxf: dxfStrings,
});

Expand Down Expand Up @@ -53,7 +53,7 @@ function getProjectName(field) {
return projectName;
}

function getImageAsBase64(field) {
function getImageBuffer(field) {
const imageBuffer = field?.data;
if (!imageBuffer) {
throw createError({
Expand All @@ -62,7 +62,7 @@ function getImageAsBase64(field) {
});
}

return imageBuffer.toString("base64");
return imageBuffer;
}

function getDxfStringArray(fields) {
Expand Down

0 comments on commit 0a48b30

Please sign in to comment.