Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
usirin committed Aug 1, 2023
1 parent 7967caf commit 5851858
Show file tree
Hide file tree
Showing 26 changed files with 1,113 additions and 106 deletions.
1 change: 1 addition & 0 deletions apps/gql/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ NODE_ENV=development
PORT=4000
COMPOSE_POSTGRES_PORT=5555
DATABASE_URL=mysql://kampus:kampus@localhost:3306/kampus?schema=public
NEXTAUTH_URL=http://localhost:3000/pasaport
8 changes: 6 additions & 2 deletions apps/gql/app/graphql/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { type NextApiRequest, type NextApiResponse } from "next";
import { createSchema, createYoga } from "graphql-yoga";

import { getServerSession } from "@kampus/next-auth";

import { createClients } from "~/clients";
import { createLoaders } from "~/loaders";
import { resolvers } from "~/schema/resolvers";

const typeDefs = readFileSync(join(process.cwd(), "schema/schema.graphql"), "utf8").toString();
const clients = createClients();

const { handleRequest } = createYoga({
const { handleRequest } = createYoga<{ req: NextApiRequest; res: NextApiResponse }>({
schema: createSchema({ typeDefs, resolvers }),
logging: "debug",
graphiql: true,
context: () => ({
context: async ({ req, res }) => ({
loaders: createLoaders(clients),
session: await getServerSession(req, res),
}),

fetchAPI: {
Expand Down
2 changes: 2 additions & 0 deletions apps/gql/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export const env = parseEnv(
{
NODE_ENV: process.env.NODE_ENV,
DATABASE_URL: process.env.DATABASE_URL,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
},
{
NODE_ENV: z.enum(["development", "test", "production"]),
DATABASE_URL: z
.string()
.url()
.default("mysql://kampus:kampus@localhost:3306/kampus?schema=public&connect_timeout=300"),
NEXTAUTH_URL: z.string().url().default("http://localhost:3000/pasaport"),
}
);
1 change: 1 addition & 0 deletions apps/gql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@graphql-tools/schema": "9.0.19",
"@kampus/gql-utils": "*",
"@kampus/next-auth": "^0.0.0",
"@kampus/prisma": "*",
"@kampus/sozluk-content": "*",
"@kampus/std": "*",
Expand Down
53 changes: 38 additions & 15 deletions apps/gql/schema/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
scalar Date
scalar DateTime

interface Node {
id: ID!
}

interface Actor {
id: ID!
name: String
profilePicture: Image
}

type Query {
# we need to have a way to encode the typename into id
# so that `Query.node` can decode it and figure out what to resolve
node(id: ID!): Node

viewer: Viewer

user(id: ID, username: String): User
sozluk: SozlukQuery!
pano: PanoQuery!
}

interface Node {
id: ID!
type Image {
url(height: Int, width: Int): String!
altText: String
}

type PageInfo {
Expand All @@ -22,9 +35,17 @@ type PageInfo {
startCursor: String
}

type User implements Node {
type Viewer {
actor: Actor
panoFeed(first: Int, after: String): PanoPostConnection
sozlukFeed(first: Int, after: String): SozlukTermConnection
}

type User implements Node & Actor {
id: ID!
username: String!
name: String
profilePicture: Image

panoPosts(
after: String
Expand Down Expand Up @@ -93,12 +114,9 @@ type PanoPost implements Node {
content: String
createdAt: DateTime!
owner: User
comments(
after: String
before: String
first: Int
last: Int
): PanoCommentConnection
comments(after: String, before: String, first: Int, last: Int): PanoCommentConnection

commentCount: Int
}

type PanoPostConnection {
Expand All @@ -119,12 +137,7 @@ type PanoComment implements Node {
owner: User
post: PanoPost
parent: PanoComment
comments(
after: String
before: String
first: Int
last: Int
): PanoCommentConnection
comments(after: String, before: String, first: Int, last: Int): PanoCommentConnection
createdAt: DateTime!
}

Expand All @@ -139,3 +152,13 @@ type PanoCommentEdge {
cursor: String!
node: PanoComment
}

# type Mutation {
# createPanoPost(input: CreateTodoInput!): CreateTodoPayload
# }

input CreateTodoInput {
title: String!
content: String
url: String
}
10 changes: 10 additions & 0 deletions apps/gql/schema/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export type Scalars = {
DateTime: { input: string; output: string };
};

export type CreateTodoInput = {
content: InputMaybe<Scalars["String"]["input"]>;
title: Scalars["String"]["input"];
url: InputMaybe<Scalars["String"]["input"]>;
};

export type Node = {
id: Scalars["ID"]["output"];
};
Expand Down Expand Up @@ -71,6 +77,7 @@ export type PanoCommentEdge = {

export type PanoPost = Node & {
__typename?: "PanoPost";
commentCount: Maybe<Scalars["Int"]["output"]>;
comments: Maybe<PanoCommentConnection>;
content: Maybe<Scalars["String"]["output"]>;
createdAt: Scalars["DateTime"]["output"];
Expand Down Expand Up @@ -301,6 +308,7 @@ export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = R
/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = ResolversObject<{
Boolean: ResolverTypeWrapper<Scalars["Boolean"]["output"]>;
CreateTodoInput: CreateTodoInput;
Date: ResolverTypeWrapper<Scalars["Date"]["output"]>;
DateTime: ResolverTypeWrapper<Scalars["DateTime"]["output"]>;
ID: ResolverTypeWrapper<Scalars["ID"]["output"]>;
Expand Down Expand Up @@ -328,6 +336,7 @@ export type ResolversTypes = ResolversObject<{
/** Mapping between all available schema types and the resolvers parents */
export type ResolversParentTypes = ResolversObject<{
Boolean: Scalars["Boolean"]["output"];
CreateTodoInput: CreateTodoInput;
Date: Scalars["Date"]["output"];
DateTime: Scalars["DateTime"]["output"];
ID: Scalars["ID"]["output"];
Expand Down Expand Up @@ -425,6 +434,7 @@ export type PanoPostResolvers<
ContextType = KampusGQLContext,
ParentType extends ResolversParentTypes["PanoPost"] = ResolversParentTypes["PanoPost"]
> = ResolversObject<{
commentCount: Resolver<Maybe<ResolversTypes["Int"]>, ParentType, ContextType>;
comments: Resolver<
Maybe<ResolversTypes["PanoCommentConnection"]>,
ParentType,
Expand Down
7 changes: 7 additions & 0 deletions apps/gql/schema/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { type NextApiRequest, type NextApiResponse } from "next";

import { type Session } from "@kampus/next-auth";

import { type DataLoaders } from "~/loaders";

export interface KampusGQLContext {
req: NextApiRequest;
res: NextApiResponse;
loaders: DataLoaders;
session: Session | null;
}
3 changes: 3 additions & 0 deletions apps/kampus/.env2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# update with the url after running `npm run dev` under `apps/gql`
NEXT_PUBLIC_GQL_URL=http://gql.localhost.kamp.us:3001/graphql
NEXTAUTH_URL=http://localhost:3000/pasaport
22 changes: 15 additions & 7 deletions apps/kampus/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import Link from "next/link";

import { getServerSession } from "@kampus/next-auth";

import { PasaportSignIn, PasaportSignOut } from "~/features/pasaport";

export default async function Home() {
const session = await getServerSession();

return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
selam kampus
{session ? (
<Link href="/pasaport/signout">logout</Link>
) : (
<Link href="/pasaport/signin">login</Link>
)}
{session ? <PasaportSignOut /> : <PasaportSignIn />}
<pre>{JSON.stringify(session, null, 2)}</pre>
</main>
);
}

const IateeComponent = () => {
const [count, setCount] = useState(0);

useEffect(() => {
setInterval(() => {
setCount(count + 1)
}, 1000)
}, [count])

return <div>{count}</div>;
};
85 changes: 56 additions & 29 deletions apps/kampus/app/pano/features/post-list/PostItem.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
"use client";

import NextLink from "next/link";
import { graphql, useFragment } from "react-relay";

import { cn } from "@kampus/ui-next/utils";

import { MoreOptionsDropdown } from "./MoreOptions";
import { TimeAgo } from "~/../../packages/ui";
import { type PostItem_post$key } from "./__generated__/PostItem_post.graphql";
import { UpvoteButton } from "./PostUpvoteButton";

type Post = {
__typename?: "PanoPost";
content: string;
createdAt: string;
id: string;
owner: string;
title: string;
url: string;
};

type PostItemProps = {
post: Post;
showContent?: boolean;
};
// import { MoreOptionsDropdown } from "./MoreOptions";

interface LinkProps {
href: string;
title: string;
children: string;
className?: string;
}

const Link = ({ href, title, className }: LinkProps) => {
const Link = ({ href, children: title, className }: LinkProps) => {
return (
<NextLink className={cn("text-muted-foreground hover:underline", className)} href={href}>
<NextLink className={cn("hover:underline", className)} href={href}>
{title}
</NextLink>
);
};

const usePanoPostFragment = (key: PostItem_post$key | null) =>
useFragment(
graphql`
fragment PostItem_post on PanoPost {
id
title
content
url
createdAt
id
site
owner {
username
}
}
`,
key
);

interface PostItemProps {
post: PostItem_post$key;
showContent?: boolean;
}

export const PostItem = (props: PostItemProps) => {
const post = usePanoPostFragment(props.post);

if (!post) {
return null;
}

return (
<div className="mr-1 flex h-full gap-1 border-l-2">
<div className="ml-1 flex h-full">
<UpvoteButton upvoteCount={5} isUpvoted={false} disabled={false} isVoting={false} />
</div>
<section className="flex h-full items-center gap-2 rounded">
<UpvoteButton upvoteCount={5} isUpvoted={false} disabled={false} isVoting={false} />

<div className="flex w-full flex-col justify-center">
<div className="flex items-center gap-1 align-baseline">
<Link title={props.post.title} href={props.post.url} />
<Link className="text-sm" title="wow.sh" href={props.post.url} />
<Link className="font-semibold" href={post.url ?? ""}>
{post.title}
</Link>
<Link className="text-sm" href={post.url ?? ""}>
{post.site ?? ""}
</Link>
</div>
<div className="flex items-center gap-1 text-sm">
<div>@{props.post.owner} |</div>
<div>{<Link title="0 yorum" href={`/pano/post/${props.post.id}/`} />} |</div>
<div>{props.post.createdAt} |</div>
<MoreOptionsDropdown post={props.post} shareUrl={props.post.url} />
<div>@{post.owner?.username} |</div>
<div>
<Link href={`/pano/post/${post.id}`}>0 yorum</Link> |
</div>
<TimeAgo date={new Date(post.createdAt as string)} />
</div>
</div>
</div>
</section>
);
};
8 changes: 3 additions & 5 deletions apps/kampus/app/pano/features/post-list/PostUpvoteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export const UpvoteButton = (props: UpvoteProps) => {
const combinedStyle = cn(upvoteStyle, opacity);

return (
<Button className="flex h-full items-center pt-3" variant="ghost">
<div className="flex flex-col items-center justify-center">
<Triangle className={combinedStyle} size={12} />
{`${props.upvoteCount}`}
</div>
<Button className="flex h-full flex-col" variant="outline">
<Triangle className={combinedStyle} size={12} />
{props.upvoteCount}
</Button>
);
};
Loading

0 comments on commit 5851858

Please sign in to comment.