Skip to content

Commit

Permalink
feat: ✨ implement paste to post
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan6erbond committed May 7, 2023
1 parent 7abb729 commit ff2e237
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/pages/posts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import Layout from "@/components/layout";
import PostCard from "@/components/postCard";
import { useCreatePost } from "@/hooks/useCreatePost";
import { usePasteFiles } from "@/hooks/usePasteFiles";
import { usePocketBase } from "@/pocketbase";
import { useAuth } from "@/pocketbase/auth";
import { Post } from "@/pocketbase/models";
import { MEDIA_MIME_TYPE } from "@/utils/mediaTypes";
import { Skeleton, Stack, Text } from "@mantine/core";
import { useIntersection } from "@mantine/hooks";
import { useRouter } from "next/router";
import { useEffect } from "react";
import { useInfiniteQuery } from "react-query";

export default function Posts() {
const router = useRouter();
const pb = usePocketBase();
const { user } = useAuth();
const {
isLoading,
error,
Expand All @@ -30,6 +37,33 @@ export default function Posts() {
}
);

const { uploading, createPost: _createPost } = useCreatePost({
acceptTypes: MEDIA_MIME_TYPE,
});

const createPost = (files: File[]) =>
_createPost({
title: "",
author: user?.id!,
files: files.map((file) => ({
file: file,
name: file.name,
author: user?.id!,
description: "",
})),
}).then(async (post) => {
if (!post) {
return;
}

router.push("/posts/" + post.id);
});

usePasteFiles({
acceptTypes: MEDIA_MIME_TYPE,
onPaste: (files) => user && createPost(files),
});

const { ref, entry } = useIntersection();

useEffect(() => {
Expand Down

0 comments on commit ff2e237

Please sign in to comment.