+
+
);
}
-const Tiptap = ({ defaultValue }) => {
+const Tiptap = ({ handleContentChange, defaultValue }) => {
const editor = useEditor({
extensions: [
StarterKit.configure({
@@ -134,16 +154,16 @@ const Tiptap = ({ defaultValue }) => {
inline: true
})
],
- content: defaultValue
- ? defaultValue
- : `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla malesuada tortor nec purus viverra, ac laoreet nulla hendrerit. Proin ac vehicula lacus. Donec nulla diam, volutpat eu interdum non, pharetra non mi. In tempor nisi augue, vel volutpat lorem gravida id. Quisque sodales augue in aliquet lacinia. Phasellus interdum convallis orci, sollicitudin pharetra enim fringilla eu. Pellentesque suscipit laoreet ante ut luctus. Etiam sagittis massa id magna efficitur volutpat. Aenean id nulla ut tellus porttitor sagittis ac ut nunc. Fusce non velit vitae purus aliquam finibus convallis vitae justo. In pellentesque risus risus, vitae tincidunt augue iaculis eget. Morbi sed risus lobortis, euismod augue sit amet, lobortis sem.
-
- Nunc vitae enim mauris. Aliquam volutpat dignissim diam, at sodales neque rutrum at. Etiam vestibulum ut orci imperdiet interdum. Duis ut venenatis purus. Aenean ac ultrices sapien. Curabitur sed diam nulla. Nunc ultrices, nisi vitae facilisis dapibus, augue nisi feugiat nisl, id sodales quam libero a sapien. Aliquam dolor justo, gravida rutrum leo in, hendrerit pulvinar elit. Quisque laoreet diam arcu, vel congue quam ullamcorper non. Quisque elit elit, condimentum nec tristique efficitur, lacinia id magna. Donec nec nibh eu nulla vestibulum efficitur. In tempus condimentum tempor. Aliquam eu ligula sed libero aliquam facilisis. Phasellus porttitor accumsan risus dictum placerat. Aenean suscipit velit at odio imperdiet, quis sodales dui molestie.`,
+ content: defaultValue ? defaultValue : '',
autofocus: true,
editorProps: {
attributes: {
class: 'prose focus:outline-none'
}
+ },
+ onUpdate: ({ editor }) => {
+ console.log('update');
+ handleContentChange(editor.getHTML());
}
});
diff --git a/publish-frontend/src/lib/invite-user.js b/publish-frontend/src/lib/invite-user.js
index b385e3328..e31d9f02a 100644
--- a/publish-frontend/src/lib/invite-user.js
+++ b/publish-frontend/src/lib/invite-user.js
@@ -23,5 +23,4 @@ export async function inviteUser(email, token) {
console.error(`inviteUser Failed. email: ${email}, Error: `, error);
throw new Error(`inviteUser Failed. email: ${email}, Error: ${error}`);
}
-
}
diff --git a/publish-frontend/src/lib/posts.js b/publish-frontend/src/lib/posts.js
index f36df705b..5ac1550bb 100644
--- a/publish-frontend/src/lib/posts.js
+++ b/publish-frontend/src/lib/posts.js
@@ -68,15 +68,14 @@ export async function createPost(JSONdata, token) {
// Tell the server we're sending JSON.
headers: {
'Content-Type': 'application/json',
+ accept: 'application/json',
Authorization: `Bearer ${token}`
},
// Body of the request is the JSON data we created above.
body: JSONdata
};
-
// Send the form data to our forms API and get a response.
const res = await fetch(endpoint, options);
-
if (!res.ok) {
throw new Error('createPost Failed');
}
diff --git a/publish-frontend/src/pages/api/auth/[...nextauth].js b/publish-frontend/src/pages/api/auth/[...nextauth].js
index 7d3296ceb..bd80807c6 100644
--- a/publish-frontend/src/pages/api/auth/[...nextauth].js
+++ b/publish-frontend/src/pages/api/auth/[...nextauth].js
@@ -92,7 +92,7 @@ export const authOptions = {
// Add the role name to session JWT
token.name = userData?.username || null;
token.userRole = userData?.role?.name || null;
- console.log('token.userRole:', token.userRole);
+ token.id = userData?.id || null;
}
}
// The returned value will be encrypted, and it is stored in a cookie.
@@ -105,6 +105,7 @@ export const authOptions = {
// Decrypt the token in the cookie and return needed values
session.user.jwt = token.jwt; // JWT token to access the Strapi API
session.user.role = token.userRole;
+ session.user.id = token.id;
return session;
}
},
diff --git a/publish-frontend/src/pages/index.js b/publish-frontend/src/pages/index.js
index 2f8c39181..b3faadb3a 100644
--- a/publish-frontend/src/pages/index.js
+++ b/publish-frontend/src/pages/index.js
@@ -172,7 +172,7 @@ export default function IndexPage({ posts, users, tags }) {
{posts.data.map(post => {
const title = post.attributes.title;
- const name = post.attributes.author.data.attributes.name;
+ const name = 'sem';
const tag = post.attributes.tags.data[0]?.attributes.name;
const relativeUpdatedAt = intlFormatDistance(
new Date(post.attributes.updatedAt),
diff --git a/publish-frontend/src/pages/posts/[postId].js b/publish-frontend/src/pages/posts/[postId].js
index 32b7e34f4..5fc35f108 100644
--- a/publish-frontend/src/pages/posts/[postId].js
+++ b/publish-frontend/src/pages/posts/[postId].js
@@ -1,10 +1,8 @@
import PostForm from '@/components/post-form';
-import { getPost, updatePost } from '@/lib/posts';
+import { getPost } from '@/lib/posts';
import { getTags } from '@/lib/tags';
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import { getServerSession } from 'next-auth/next';
-import { useSession } from 'next-auth/react';
-import { useState } from 'react';
export async function getServerSideProps(context) {
const session = await getServerSession(context.req, context.res, authOptions);
@@ -12,65 +10,14 @@ export async function getServerSideProps(context) {
const { data: tags } = await getTags(session.user.jwt);
const { data: post } = await getPost(postId, session.user.jwt);
return {
- props: { tags, post }
+ props: { tags, post, author: session?.user?.id }
};
}
-export default function EditPostPage({ tags, post }) {
- // Get auth data from the session
- const { data: session } = useSession();
- // declare state variables
- const [content, setContent] = useState(post.attributes.body);
-
- const handleContentChange = updatedContent => {
- setContent(updatedContent);
- };
-
- // Handles the submit event on form submit.
- const handleSubmit = async (event, session) => {
- // Stop the form from submitting and refreshing the page.
- event.preventDefault();
-
- // Construct the data to be sent to the server
- const data = {
- // Need to nest in data object because Strapi expects so
- data: {
- title: event.target.title.value,
- body: content, // Get the content from the state
- slug: event.target.slug.value
- }
- };
-
- // Send the data to the Strapi server in JSON format.
- const JSONdata = JSON.stringify(data);
-
- // Bearer token for authentication
- const token = session.user.jwt;
-
- // Sending request
- try {
- const result = await updatePost(post.id, JSONdata, token);
- console.log('updatePost response: ', JSON.stringify(result));
- alert('Saved!');
- } catch (error) {
- console.error('createPost Error:', error);
- alert('Failed to save the post');
- }
- };
-
- // loading screen
- if (!post) {
- return