Skip to content

Commit

Permalink
add view source button, clear input
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Oct 20, 2024
1 parent 23ccd2f commit 877ec04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/social/compose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { useCreatePost } from "@/lib/social";
import { useState } from "react";

export default function Compose() {
const mutation = useCreatePost();

const [text, setText] = useState("");
const mutation = useCreatePost({ cleanup: () => setText("") });

const handleSubmit = async () => {
mutation.mutate({ content: { text, type: "md" } });
Expand Down
5 changes: 4 additions & 1 deletion src/lib/social.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ export function useGetPosts(limit: number = 10, order: string = "desc") {
});
}

export function useCreatePost() {
export function useCreatePost({ cleanup }: { cleanup?: () => void }) {
const { wallet } = useWallet();

return useMutation({
onSuccess: () => {
// Invalidate and refetch the "posts" query
queryClient.invalidateQueries({ queryKey: ["posts"] });
if (cleanup) {
cleanup();
}
},
mutationFn: async ({ content }: { content: any }) => {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function RootComponent() {
<NearProvider>
<div className="min-h-screen bg-gradient-to-br from-orange-400 to-purple-800">
<div className="container mx-auto px-4 py-8">
<div className="flex justify-end p-1">
<a href="https://github.com/NEARBuilders/decentralized-social" target="_blank" className="text-white">
view source
</a>
</div>
<div className="overflow-hidden rounded-lg bg-white shadow-lg">
<Header />
<main className="container mx-auto px-4 py-8">
Expand Down

0 comments on commit 877ec04

Please sign in to comment.