Skip to content

Commit

Permalink
Add README to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlevay committed Feb 3, 2025
1 parent 1d83997 commit e696994
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "readme" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"title" TEXT NOT NULL,
"url" TEXT NOT NULL,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"published_at" TIMESTAMPTZ(6),

CONSTRAINT "readme_pkey" PRIMARY KEY ("id")
);
12 changes: 12 additions & 0 deletions src/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1075,4 +1075,16 @@ model ShoppableAccessPolicy {
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
@@map("shoppable_access_policies")
}

/// @@allow('read', true)
model Readme {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
title String
url String
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @map("updated_at") @db.Timestamptz(6)
publishedAt DateTime? @map("published_at") @db.Timestamptz(6)
@@map("readme")
}
12 changes: 12 additions & 0 deletions src/database/schema.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -1154,4 +1154,16 @@ model ShoppableAccessPolicy {
// only managers can delete (should very rarely be done)
@@allow("delete", auth().memberId == shoppable.authorId || has(auth().policies, "webshop:manage"))
@@map("shoppable_access_policies")
}

model Readme {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String
url String
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @map("updated_at") @db.Timestamptz(6)
publishedAt DateTime? @map("published_at") @db.Timestamptz(6)

@@map("readme")
@@allow("read", true)
}
100 changes: 100 additions & 0 deletions src/database/seed/.snaplet/dataModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7866,6 +7866,106 @@
}
]
},
"readme": {
"id": "public.readme",
"schemaName": "public",
"tableName": "readme",
"fields": [
{
"id": "public.readme.id",
"name": "id",
"columnName": "id",
"type": "uuid",
"isRequired": true,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": true,
"isId": true,
"maxLength": null
},
{
"id": "public.readme.title",
"name": "title",
"columnName": "title",
"type": "text",
"isRequired": true,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": false,
"isId": false,
"maxLength": null
},
{
"id": "public.readme.url",
"name": "url",
"columnName": "url",
"type": "text",
"isRequired": true,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": false,
"isId": false,
"maxLength": null
},
{
"id": "public.readme.created_at",
"name": "created_at",
"columnName": "created_at",
"type": "timestamptz",
"isRequired": true,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": true,
"isId": false,
"maxLength": null
},
{
"id": "public.readme.updated_at",
"name": "updated_at",
"columnName": "updated_at",
"type": "timestamptz",
"isRequired": true,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": false,
"isId": false,
"maxLength": null
},
{
"id": "public.readme.published_at",
"name": "published_at",
"columnName": "published_at",
"type": "timestamptz",
"isRequired": false,
"kind": "scalar",
"isList": false,
"isGenerated": false,
"sequence": false,
"hasDefaultValue": false,
"isId": false,
"maxLength": null
}
],
"uniqueConstraints": [
{
"name": "readme_pkey",
"fields": [
"id"
],
"nullNotDistinct": false
}
]
},
"shoppable": {
"id": "public.shoppable",
"schemaName": "public",
Expand Down
7 changes: 7 additions & 0 deletions src/database/seed/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,11 @@ export const models: SeedClientOptions["models"] = {
color: () => faker.internet.color(),
},
},
readme: {
data: {
title: `README #${faker.number.int({ min: 1, max: 5 })}`,
url: "https://publuu.com/flip-book/782891/1741481/page/1?embed",
publishedAt: () => faker.date.past(),
},
},
};
2 changes: 2 additions & 0 deletions src/database/seed/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const main = async () => {

await seed.election((x) => x(5));

await seed.readme((x) => x(5));

process.exit();
};

Expand Down
15 changes: 15 additions & 0 deletions src/lib/components/home/Readme.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import type { Readme } from "@prisma/client";
export let readme: Readme;
</script>

<iframe
src={readme.url}
width="100%"
height="780"
scrolling="no"
frameborder="0"
allow="clipboard-write; autoplay; fullscreen"
class="publuuflip"
title="Readme of the month"
></iframe>
8 changes: 8 additions & 0 deletions src/lib/server/loadHomeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const loadHomeData = async ({
})
.then((res) => res !== null);

const readmePromise = prisma.readme.findFirst();

const [
news,
events,
Expand All @@ -133,6 +135,7 @@ export const loadHomeData = async ({
cafeOpen,
commitData,
hasActiveMandate,
readme,
] = await Promise.allSettled([
newsPromise,
eventsPromise,
Expand All @@ -141,6 +144,7 @@ export const loadHomeData = async ({
cafeOpenPromise,
commitPromise,
hasActiveMandatePromise,
readmePromise,
]);
if (news.status === "rejected") {
throw error(500, "Failed to fetch news");
Expand All @@ -163,6 +167,9 @@ export const loadHomeData = async ({
if (hasActiveMandate.status === "rejected") {
throw error(500, "Failed to fetch mandate data");
}
if (readme.status === "rejected") {
throw error(500, "Failed to fetch readme");
}

return {
files: { next: nextBoardMeetingFiles, last: lastBoardMeetingFiles },
Expand All @@ -176,5 +183,6 @@ export const loadHomeData = async ({
commitCount: commitData.value.commitCount,
latestCommit: commitData.value.latestCommit,
hasActiveMandate: hasActiveMandate.value,
readme: readme.value,
};
};
7 changes: 7 additions & 0 deletions src/routes/(app)/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { getFullName } from "$lib/utils/client/member";
import SetPageTitle from "$lib/components/nav/SetPageTitle.svelte";
import * as m from "$paraglide/messages";
import Readme from "$lib/components/home/Readme.svelte";
export let data: PageData;
</script>

Expand Down Expand Up @@ -63,4 +64,10 @@
<section class="md:col-span-3 xl:col-span-3">
<Documents files={data.files} />
</section>

<section class="md:col-span-3 xl:col-span-5">
{#if data.readme}
<Readme readme={data.readme} />
{/if}
</section>
</div>

0 comments on commit e696994

Please sign in to comment.