diff --git a/app/subscriber/src/features/my-reports/edit/content/ContentEditForm.tsx b/app/subscriber/src/features/my-reports/edit/content/ContentEditForm.tsx index 44b0c150a..b4e53b592 100644 --- a/app/subscriber/src/features/my-reports/edit/content/ContentEditForm.tsx +++ b/app/subscriber/src/features/my-reports/edit/content/ContentEditForm.tsx @@ -6,12 +6,9 @@ import { IContentValidationErrors } from 'features/my-reports/interfaces/IConten import { toForm } from 'features/my-reports/utils'; import { formatDate } from 'features/utils'; import React from 'react'; -import { FaToggleOff, FaToggleOn } from 'react-icons/fa'; import { useApp, useContent, useReports } from 'store/hooks'; -import { useTonePool } from 'store/hooks/subscriber/useTonePool'; -import { Col, ContentTypeName, IContentModel, IContentTonePoolModel, ToggleButton } from 'tno-core'; +import { Col, ContentTypeName, IContentModel, IContentTonePoolModel } from 'tno-core'; -import { defaultContentTonePool } from '../constants/defaultContentTonePool'; import { useReportEditContext } from '../ReportEditContext'; import { ContentActions, ContentForm, UserContentForm } from './stories'; import * as styled from './styled'; @@ -32,7 +29,7 @@ export const ContentEditForm = React.forwardRef { - setIsUserSentiment((prev) => !prev); - }, []); + // const toggleSentiment = React.useCallback(() => { + // setIsUserSentiment((prev) => !prev); + // }, []); React.useEffect(() => { const updatedUserFormTonePool = @@ -100,22 +97,22 @@ export const ContentEditForm = React.forwardRef { - try { - const newTonePool = await addMyTonePool({ - ...defaultContentTonePool, - name: `${userId}`, - ownerId: userId, - }); - return newTonePool; - } catch (error) { - console.error('Error creating tone pool:', error); - } finally { - } - }, - [addMyTonePool], - ); + // const createTonePool = React.useCallback( + // async (userId: number) => { + // try { + // const newTonePool = await addMyTonePool({ + // ...defaultContentTonePool, + // name: `${userId}`, + // ownerId: userId, + // }); + // return newTonePool; + // } catch (error) { + // console.error('Error creating tone pool:', error); + // } finally { + // } + // }, + // [addMyTonePool], + // ); const handleAddUpdateContent = React.useCallback( async (values: IReportForm, row: IReportInstanceContentForm) => { @@ -127,24 +124,24 @@ export const ContentEditForm = React.forwardRef tp.ownerId === userId) ?? defaultContentTonePool; - if (userTonePool.id === 0) { - const newTonePool = await createTonePool(userId); + // let userTonePool: IContentTonePoolModel = + // content?.tonePools.find((tp) => tp.ownerId === userId) ?? defaultContentTonePool; + // if (userTonePool.id === 0) { + // const newTonePool = await createTonePool(userId); - if (newTonePool) { - userTonePool = { - ...userTonePool, - id: newTonePool.id, - }; - } - if (content?.tonePools) { - content.tonePools = [ - ...content.tonePools.filter((tp) => tp.ownerId !== userId), - userTonePool, - ]; - } - } + // if (newTonePool) { + // userTonePool = { + // ...userTonePool, + // id: newTonePool.id, + // }; + // } + // if (content?.tonePools) { + // content.tonePools = [ + // ...content.tonePools.filter((tp) => tp.ownerId !== userId), + // userTonePool, + // ]; + // } + // } if (err.hasErrors) return null; try { contentResult = !content.id @@ -228,7 +225,6 @@ export const ContentEditForm = React.forwardRef - } off={} onClick={toggleSentiment} @@ -322,7 +317,7 @@ export const ContentEditForm = React.forwardRef + /> */} , 'content'> { /** The content being edited */ content?: IContentModel; @@ -65,11 +61,11 @@ export const ContentForm: React.FC = ({ : content.summary : content?.body, }; - const userDefaultContentTonePool = { - ...defaultContentTonePool, - ownerId: userId, - name: `${userId}`, - }; + // const userDefaultContentTonePool = { + // ...defaultContentTonePool, + // ownerId: userId, + // name: `${userId}`, + // }; React.useEffect(() => { let isMounted = true; @@ -97,36 +93,36 @@ export const ContentForm: React.FC = ({ if (!content) return null; - const handleToneSelect = (value: number) => { - const updatedTonePool: IContentTonePoolModel = { - ...myTonePool, - ownerId: - myTonePool?.ownerId !== undefined && myTonePool?.ownerId !== 0 - ? myTonePool.ownerId - : userId, - id: myTonePool?.id ?? 0, - isPublic: myTonePool?.isPublic ?? true, - name: - myTonePool?.name !== undefined && myTonePool?.name !== '' ? myTonePool?.name : `${userId}`, - value, - sortOrder: myTonePool?.sortOrder ?? 0, - isEnabled: myTonePool?.isEnabled ?? true, - description: myTonePool?.description ?? '', - }; + // const handleToneSelect = (value: number) => { + // const updatedTonePool: IContentTonePoolModel = { + // ...myTonePool, + // ownerId: + // myTonePool?.ownerId !== undefined && myTonePool?.ownerId !== 0 + // ? myTonePool.ownerId + // : userId, + // id: myTonePool?.id ?? 0, + // isPublic: myTonePool?.isPublic ?? true, + // name: + // myTonePool?.name !== undefined && myTonePool?.name !== '' ? myTonePool?.name : `${userId}`, + // value, + // sortOrder: myTonePool?.sortOrder ?? 0, + // isEnabled: myTonePool?.isEnabled ?? true, + // description: myTonePool?.description ?? '', + // }; - if (content?.id) { - onContentChange?.({ - ...content, - tonePools: [...(content.tonePools || []), updatedTonePool], - }); - } else { - console.error('Content ID is missing or invalid.'); - } - }; + // if (content?.id) { + // onContentChange?.({ + // ...content, + // tonePools: [...(content.tonePools || []), updatedTonePool], + // }); + // } else { + // console.error('Content ID is missing or invalid.'); + // } + // }; - const userContentTonePool: IContentTonePoolModel = - content?.tonePools?.find((pool: IContentTonePoolModel) => pool.ownerId === userId) || - userDefaultContentTonePool; + // const userContentTonePool: IContentTonePoolModel = + // content?.tonePools?.find((pool: IContentTonePoolModel) => pool.ownerId === userId) || + // userDefaultContentTonePool; return show === 'none' ? null : ( @@ -221,9 +217,9 @@ export const ContentForm: React.FC = ({ onContentChange?.(values); }} /> - {isUserSentiment && ( + {/* {isUserSentiment && ( - )} + )} */} ); diff --git a/libs/net/dal/Extensions/ContentExtensions.cs b/libs/net/dal/Extensions/ContentExtensions.cs index 7a7f8b75c..2c17e73cb 100644 --- a/libs/net/dal/Extensions/ContentExtensions.cs +++ b/libs/net/dal/Extensions/ContentExtensions.cs @@ -163,21 +163,17 @@ public static TNOContext UpdateContext(this TNOContext context, Content original } }); + oTonePools.Except(updated.TonePoolsManyToMany).ForEach(a => + { + context.Entry(a).State = EntityState.Deleted; + }); updated.TonePoolsManyToMany.ForEach(a => { var current = a.TonePoolId != 0 ? oTonePools.FirstOrDefault(o => o.TonePoolId == a.TonePoolId) : null; - + // If no matching tone pool exists, add it to the original list if (current == null) - { - a.TonePool ??= context.TonePools.FirstOrDefault(tp => tp.Id == a.TonePoolId); - - if (a.TonePool != null && - !original.TonePoolsManyToMany.Any(x => x.TonePool != null && x.TonePool.Id == a.TonePool.Id)) - { - original.TonePoolsManyToMany.Add(a); - } - } + original.TonePoolsManyToMany.Add(a); // If a matching tone pool is found but the values have changed, update the values else if (current.Value != a.Value) {