chore: clean up types

This commit is contained in:
Stevan Freeborn
2023-09-11 13:49:13 -05:00
parent e29b46cdb1
commit dd17181510
5 changed files with 18 additions and 34 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { v } from 'convex/values';
import { UserDto } from './../src/app/types/index';
import {
QueryCtx,
internalMutation,
@@ -15,7 +16,7 @@ export async function userQuery(ctx: QueryCtx, clerkUserId: string) {
export const getUserByClerkId = query({
args: { clerkUserId: v.string() },
async handler(ctx, args) {
async handler(ctx, args): Promise<UserDto | 'USER_NOT_FOUND'> {
const user = await userQuery(ctx, args.clerkUserId);
if (user === null) {
+10
View File
@@ -0,0 +1,10 @@
import { Doc, Id } from '../../../convex/_generated/dataModel';
export type UserDto = {
_id: Id<'users'>;
_creationTime: number;
clerkUsername: string | null;
clerkImageUrl: string;
};
export type PostWithUserDto = Doc<'posts'> & { user: UserDto };
+2 -12
View File
@@ -2,19 +2,9 @@ import { Text } from '@codemirror/state';
import Image from 'next/image';
import { Doc, Id } from '../../convex/_generated/dataModel';
import PostContent from './PostContent';
import { PostWithUserDto } from '@/app/types';
export default function Post({
post,
}: {
post: Doc<'posts'> & {
user: {
_id: Id<'users'>;
_creationTime: number;
clerkUsername: string | null;
clerkImageUrl: string;
};
};
}) {
export default function Post({ post }: { post: PostWithUserDto }) {
const username = post.user.clerkUsername ?? post.user._id;
const createdPostDate = new Date(post._creationTime);
const postYear = createdPostDate.getFullYear();
+2 -11
View File
@@ -1,21 +1,12 @@
'use client';
import { UserDto } from '@/app/types';
import { usePaginatedQuery } from 'convex/react';
import { api } from '../../convex/_generated/api';
import { Id } from '../../convex/_generated/dataModel';
import Post from './Post';
import SpinningLoader from './SpinningLoader';
export default function UserPosts({
user,
}: {
user: {
_id: Id<'users'>;
_creationTime: number;
clerkUsername: string | null;
clerkImageUrl: string;
};
}) {
export default function UserPosts({ user }: { user: UserDto }) {
const PAGE_SIZE = 1;
const pager = usePaginatedQuery(
api.posts.getUsersPostById,
+2 -10
View File
@@ -1,17 +1,9 @@
import Image from 'next/image';
import { AiFillCalendar } from 'react-icons/ai';
import { Doc, Id } from '../../convex/_generated/dataModel';
import { UserDto } from '@/app/types';
export default function UserProfile({
user,
}: {
user: {
_id: Id<'users'>;
_creationTime: number;
clerkUsername: string | null;
clerkImageUrl: string;
};
}) {
export default function UserProfile({ user }: { user: UserDto }) {
const username = user.clerkUsername ?? user._id;
const userCreatedDate = new Date(user._creationTime);
const monthJoined = userCreatedDate.toLocaleString(undefined, {