chore: clean up types
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { v } from 'convex/values';
|
import { v } from 'convex/values';
|
||||||
|
import { UserDto } from './../src/app/types/index';
|
||||||
import {
|
import {
|
||||||
QueryCtx,
|
QueryCtx,
|
||||||
internalMutation,
|
internalMutation,
|
||||||
@@ -15,7 +16,7 @@ export async function userQuery(ctx: QueryCtx, clerkUserId: string) {
|
|||||||
|
|
||||||
export const getUserByClerkId = query({
|
export const getUserByClerkId = query({
|
||||||
args: { clerkUserId: v.string() },
|
args: { clerkUserId: v.string() },
|
||||||
async handler(ctx, args) {
|
async handler(ctx, args): Promise<UserDto | 'USER_NOT_FOUND'> {
|
||||||
const user = await userQuery(ctx, args.clerkUserId);
|
const user = await userQuery(ctx, args.clerkUserId);
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
|
|||||||
@@ -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
@@ -2,19 +2,9 @@ import { Text } from '@codemirror/state';
|
|||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { Doc, Id } from '../../convex/_generated/dataModel';
|
import { Doc, Id } from '../../convex/_generated/dataModel';
|
||||||
import PostContent from './PostContent';
|
import PostContent from './PostContent';
|
||||||
|
import { PostWithUserDto } from '@/app/types';
|
||||||
|
|
||||||
export default function Post({
|
export default function Post({ post }: { post: PostWithUserDto }) {
|
||||||
post,
|
|
||||||
}: {
|
|
||||||
post: Doc<'posts'> & {
|
|
||||||
user: {
|
|
||||||
_id: Id<'users'>;
|
|
||||||
_creationTime: number;
|
|
||||||
clerkUsername: string | null;
|
|
||||||
clerkImageUrl: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const username = post.user.clerkUsername ?? post.user._id;
|
const username = post.user.clerkUsername ?? post.user._id;
|
||||||
const createdPostDate = new Date(post._creationTime);
|
const createdPostDate = new Date(post._creationTime);
|
||||||
const postYear = createdPostDate.getFullYear();
|
const postYear = createdPostDate.getFullYear();
|
||||||
|
|||||||
@@ -1,21 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { UserDto } from '@/app/types';
|
||||||
import { usePaginatedQuery } from 'convex/react';
|
import { usePaginatedQuery } from 'convex/react';
|
||||||
import { api } from '../../convex/_generated/api';
|
import { api } from '../../convex/_generated/api';
|
||||||
import { Id } from '../../convex/_generated/dataModel';
|
|
||||||
import Post from './Post';
|
import Post from './Post';
|
||||||
import SpinningLoader from './SpinningLoader';
|
import SpinningLoader from './SpinningLoader';
|
||||||
|
|
||||||
export default function UserPosts({
|
export default function UserPosts({ user }: { user: UserDto }) {
|
||||||
user,
|
|
||||||
}: {
|
|
||||||
user: {
|
|
||||||
_id: Id<'users'>;
|
|
||||||
_creationTime: number;
|
|
||||||
clerkUsername: string | null;
|
|
||||||
clerkImageUrl: string;
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const PAGE_SIZE = 1;
|
const PAGE_SIZE = 1;
|
||||||
const pager = usePaginatedQuery(
|
const pager = usePaginatedQuery(
|
||||||
api.posts.getUsersPostById,
|
api.posts.getUsersPostById,
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { AiFillCalendar } from 'react-icons/ai';
|
import { AiFillCalendar } from 'react-icons/ai';
|
||||||
import { Doc, Id } from '../../convex/_generated/dataModel';
|
import { Doc, Id } from '../../convex/_generated/dataModel';
|
||||||
|
import { UserDto } from '@/app/types';
|
||||||
|
|
||||||
export default function UserProfile({
|
export default function UserProfile({ user }: { user: UserDto }) {
|
||||||
user,
|
|
||||||
}: {
|
|
||||||
user: {
|
|
||||||
_id: Id<'users'>;
|
|
||||||
_creationTime: number;
|
|
||||||
clerkUsername: string | null;
|
|
||||||
clerkImageUrl: string;
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const username = user.clerkUsername ?? user._id;
|
const username = user.clerkUsername ?? user._id;
|
||||||
const userCreatedDate = new Date(user._creationTime);
|
const userCreatedDate = new Date(user._creationTime);
|
||||||
const monthJoined = userCreatedDate.toLocaleString(undefined, {
|
const monthJoined = userCreatedDate.toLocaleString(undefined, {
|
||||||
|
|||||||
Reference in New Issue
Block a user