Skip to content

Commit

Permalink
fix: update local state for NewsUpdateCard edit
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhrmo committed Oct 31, 2024
1 parent 26eaf48 commit ac15ab5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/components/newsPage/cards/NewsUpdateCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { useState } from 'react';
import { SeverityLevel } from '@microsoft/applicationinsights-web';

import { NewsFeedEntry, ProjectUpdate } from '@/common/types';
Expand All @@ -22,20 +23,24 @@ interface UpdateCardProps {

export const NewsUpdateCard = (props: UpdateCardProps) => {
const { entry, onUpdate, noClamp = false } = props;
const update = entry.item as ProjectUpdate;

const initialUpdate = entry.item as ProjectUpdate;
const [update, setUpdate] = useState(initialUpdate);

const state = useEditingState();
const editingInteractions = useEditingInteractions();

const handleUpdate = async (updatedText: string) => {
try {
await updateProjectUpdate({ updateId: update.id, comment: updatedText });
setUpdate({ ...update, comment: updatedText });
onUpdate(updatedText);
editingInteractions.onSubmit();
} catch (error) {
console.error('Error updating project update:', error);
errorMessage({ message: m.components_newsPage_cards_newsCard_error_update() });
appInsights.trackException({
exception: new Error('Failed to delete project update', { cause: error }),
exception: new Error('Failed to update project update', { cause: error }),
severityLevel: SeverityLevel.Error,
});
}
Expand Down

0 comments on commit ac15ab5

Please sign in to comment.