Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open the floodgates #144

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions packages/frontpage/app/(app)/invite-only/page.tsx

This file was deleted.

34 changes: 1 addition & 33 deletions packages/frontpage/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { deleteAuthCookie, getSession, signOut } from "@/lib/auth";
import Link from "next/link";
import { Suspense } from "react";
import { Button } from "@/lib/components/ui/button";
import { isAdmin, isBetaUser } from "@/lib/data/user";
import { isAdmin } from "@/lib/data/user";
import { OpenInNewWindowIcon } from "@radix-ui/react-icons";
import { ThemeToggle } from "./_components/theme-toggle";
import {
Expand Down Expand Up @@ -34,7 +34,6 @@ export default async function Layout({
children: React.ReactNode;
}) {
const session = await getSession();
const isInBeta = await isBetaUser();
return (
<div className="container mx-auto px-4 md:px-6 pt-4 md:py-12 max-w-3xl">
<div className="flex place-content-between items-center mb-8">
Expand All @@ -55,37 +54,6 @@ export default async function Layout({
</div>
</div>

{session ? (
<div className="flex justify-between items-center bg-slate-100 dark:bg-slate-900/50 dark:text-slate-300 p-4 mb-4 gap-2 rounded-md">
<span>
{isInBeta ? (
<>
Thanks for joining the beta! There will be bugs! Please the
report them to{" "}
<a
href={`https://bsky.app/profile/${FRONTPAGE_ATPROTO_HANDLE}`}
className="font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400 dark:hover:text-indigo-300"
>
@frontpage.fyi <OpenInNewWindowIcon className="inline" />
</a>
</>
) : (
<>You&apos;re not currently part of the beta</>
)}
</span>

{!isInBeta && (
<Button
asChild
variant="ghost"
className="text-indigo-600 dark:text-indigo-400"
>
<Link href="/invite-only">Learn more</Link>
</Button>
)}
</div>
) : null}

<main className="mb-6">{children}</main>

<footer className="flex justify-between items-center text-gray-500 dark:text-gray-400">
Expand Down
4 changes: 0 additions & 4 deletions packages/frontpage/lib/data/atproto/comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "server-only";
import { ensureIsInBeta } from "../user";
import {
atprotoCreateRecord,
createAtUriParser,
Expand Down Expand Up @@ -35,7 +34,6 @@ type CommentInput = {
};

export async function createComment({ parent, post, content }: CommentInput) {
await ensureIsInBeta();
// Collapse newlines into a single \n\n and trim whitespace
const sanitizedContent = content.replace(/\n\n+/g, "\n\n").trim();
const record = {
Expand Down Expand Up @@ -66,8 +64,6 @@ export async function createComment({ parent, post, content }: CommentInput) {
}

export async function deleteComment(rkey: string) {
await ensureIsInBeta();

await atprotoDeleteRecord({
rkey,
collection: CommentCollection,
Expand Down
4 changes: 0 additions & 4 deletions packages/frontpage/lib/data/atproto/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "server-only";
import { ensureIsInBeta } from "../user";
import {
atprotoCreateRecord,
atprotoDeleteRecord,
Expand All @@ -25,7 +24,6 @@ type PostInput = {
};

export async function createPost({ title, url }: PostInput) {
await ensureIsInBeta();
const record = { title, url, createdAt: new Date().toISOString() };
PostRecord.parse(record);

Expand All @@ -40,8 +38,6 @@ export async function createPost({ title, url }: PostInput) {
}

export async function deletePost(rkey: string) {
await ensureIsInBeta();

await atprotoDeleteRecord({
rkey,
collection: PostCollection,
Expand Down
4 changes: 1 addition & 3 deletions packages/frontpage/lib/data/atproto/vote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "server-only";
import { ensureIsInBeta, ensureUser } from "../user";
import { ensureUser } from "../user";
import {
atprotoCreateRecord,
atprotoDeleteRecord,
Expand Down Expand Up @@ -37,7 +37,6 @@ export async function createVote({
subjectAuthorDid,
}: VoteInput) {
await ensureUser();
await ensureIsInBeta();
const uri = `at://${subjectAuthorDid}/${subjectCollection}/${subjectRkey}`;

const record = {
Expand All @@ -58,7 +57,6 @@ export async function createVote({

export async function deleteVote(rkey: string) {
await ensureUser();
await ensureIsInBeta();

await atprotoDeleteRecord({
collection: "fyi.unravel.frontpage.vote",
Expand Down
27 changes: 0 additions & 27 deletions packages/frontpage/lib/data/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,6 @@ export async function ensureUser() {
return user;
}

export const ensureIsInBeta = cache(async () => {
const user = await ensureUser();

if (
await db.query.BetaUser.findFirst({
where: eq(schema.BetaUser.did, user.did),
})
) {
return;
}

redirect("/invite-only");
});

export const isBetaUser = cache(async () => {
const user = await getUser();
if (!user) {
return false;
}

return Boolean(
await db.query.BetaUser.findFirst({
where: eq(schema.BetaUser.did, user.did),
}),
);
});

export const isAdmin = cache(async () => {
const user = await ensureUser();
if (!user) {
Expand Down
3 changes: 3 additions & 0 deletions packages/frontpage/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export const CommentVote = sqliteTable(
}),
);

/**
* @deprecated
*/
export const BetaUser = sqliteTable("beta_users", {
id: integer("id").primaryKey(),
createdAt: dateIsoText("created_at").notNull(),
Expand Down
Loading