Skip to content

Commit

Permalink
Replace description with lego editor field
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Feb 19, 2024
1 parent 399f744 commit 41049f7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
8 changes: 4 additions & 4 deletions app/actions/ForumActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function createForum(forum: CreateForum) {
types: Forum.CREATE,
endpoint: '/forums/',
method: 'POST',
body: { ...forum },
body: forum,
schema: forumSchema,
meta: {
errorMessage: 'Opprettelse av forum feilet',
Expand Down Expand Up @@ -107,7 +107,7 @@ export function createThread(thread: CreateThread) {
types: Thread.CREATE,
endpoint: '/threads/',
method: 'POST',
body: { ...thread },
body: thread ,
schema: threadSchema,
meta: {
errorMessage: 'Opprettelse av tråd feilet',
Expand All @@ -122,8 +122,8 @@ export function editThread(thread: UpdateThread) {
method: 'PUT',
body: {
title: thread.title,
description: thread.description,
forum: thread.forum || undefined,
content: thread.content,
forum: thread.forum,
},
meta: {
errorMessage: 'Endring av tråd feilet',
Expand Down
4 changes: 2 additions & 2 deletions app/routes/articles/components/ArticleEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ const ArticleEditor = () => {
id="article-title"
/>
<Field
placeholder="Skriv artikkelen din her ..."
placeholder="Skriv tråden din her"
name="content"
label="Innhold"
label="Beskrivelse"
component={EditorField.Field}
/>

Expand Down
6 changes: 3 additions & 3 deletions app/routes/forum/components/ThreadDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useUserContext } from 'app/routes/app/AppRoute';
import { useAppDispatch, useAppSelector } from 'app/store/hooks';
import type Comment from 'app/store/models/Comment';
import type { DetailedThread } from 'app/store/models/Forum';
import DisplayContent from 'app/components/DisplayContent';

const ThreadDetail = () => {
const { threadId } = useParams<{ threadId: string }>();
Expand Down Expand Up @@ -50,9 +51,8 @@ const ThreadDetail = () => {
</NavigationLink>
)}
</NavigationTab>

<h1> {thread.title}</h1>
{thread.description}
<h1>{thread.title}</h1>
<DisplayContent content={thread.content} />
<h4>
Tråd startet av av{' '}
<Link to={`/users/${thread.createdBy?.username}`}>
Expand Down
28 changes: 15 additions & 13 deletions app/routes/forum/components/ThreadEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
fetchThread,
} from 'app/actions/ForumActions';
import { Content } from 'app/components/Content';
import { TextInput, Form, TextArea, LegoFinalForm } from 'app/components/Form';
import {
TextInput,
Form,
TextArea,
LegoFinalForm,
EditorField,
} from 'app/components/Form';
import { SubmitButton } from 'app/components/Form/SubmitButton';
import { selectThreadsById } from 'app/reducers/threads';
import { useAppDispatch, useAppSelector } from 'app/store/hooks';
Expand Down Expand Up @@ -53,11 +59,10 @@ const ThreadEditor = () => {

const onSubmit = (data: UpdateThread | CreateThread) => {
const resolveForumId = forumId ? parseInt(forumId) : thread?.forum;
console.log(resolveForumId);
const body = {
...(isNew ? {} : { id: parseInt(threadId) }),
title: data.title,
description: data.description,
content: data.content,
forum: resolveForumId,
};

Expand All @@ -69,7 +74,7 @@ const ThreadEditor = () => {

const handleDeleteThread = async () => {
if (thread) {
await dispatch(deleteThread(parseInt(threadId))).then(() => {
dispatch(deleteThread(parseInt(threadId))).then(() => {
navigate(`/forum/${thread.forum}`);
});
}
Expand All @@ -89,18 +94,15 @@ const ThreadEditor = () => {
id="thread-title"
/>
<Field
placeholder="En beskrivelse av tråden"
name="description"
label="Beskrivelse"
component={TextArea.Field}
id="thread-description"
placeholder="Skriv artikkelen din her ..."
name="content"
label="Innhold"
component={EditorField.Field}
/>

{/* Action buttons */}
<Flex wrap>
<Button
flat
onClick={() => navigate(`/forum/threads/${thread.forum}`)}
>
<Button flat onClick={() => navigate(`/forum/${thread.forum}`)}>
Avbryt
</Button>
<SubmitButton>
Expand Down
7 changes: 6 additions & 1 deletion app/routes/forum/components/ThreadListEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ const ThreadListEntry = ({
<Link to={`/forum/threads/${thread.id}`}>
<h2>{thread.title}</h2>
<div>
<h4>{thread.description}</h4>
<h4>
{thread?.content.replace(/<\/?[^>]+(>|$)/g, '').substring(0, 100)}
{thread?.content.replace(/<\/?[^>]+(>|$)/g, '').length >= 100
? '...'
: ''}
</h4>
</div>
</Link>
</Flex>
Expand Down
12 changes: 6 additions & 6 deletions app/store/createRootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ const createRootReducer = () => {
events,
feedActivities,
feeds,
followersCompany,
followersEvent,
followersUser,
forums,
frontpage,
imageGalleryEntries,
galleries,
galleryPictures,
groups,
imageGalleryEntries,
joblistings,
meetingInvitations,
meetings,
Expand All @@ -94,13 +98,9 @@ const createRootReducer = () => {
surveys,
tags,
theme,
threads,
toasts,
users,
followersCompany,
followersUser,
followersEvent,
forums,
threads,
});
};

Expand Down
4 changes: 2 additions & 2 deletions app/store/models/Forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Dateish, ID } from 'app/models';

export interface CreateThread {
title: string;
description: string;
content: string;
forum: ID;
}

Expand All @@ -16,7 +16,7 @@ export interface UpdateThread extends CreateThread {
export interface PublicThread {
id: ID;
title: string;
description: string;
content: string;
createdAt: Dateish; // Assuming created_at is serialized as ISO date string
forum: ID; // Forum ID
}
Expand Down

0 comments on commit 41049f7

Please sign in to comment.