Skip to content

Commit a352374

Browse files
gtryusGreg Trihus
andauthored
TT-7019 Implement publish button functionality in PlanView and ScriptureTable components (#191)
- Refactor ConfirmPublishDialog to utilize context and improve string handling for media and plan publishing. Remove unnecessary props and integrate new selectors for better state management. - Display dialog for publish options - Refactor PlanView to replace handleOpenPublishDialog with handlePublish, enhancing publish functionality and integrating confirmation dialog for publishing actions. - Update localized strings for improved user feedback during publishing. Co-authored-by: Greg Trihus <gtryus@gmail.com>
1 parent fef37b4 commit a352374

File tree

6 files changed

+443
-137
lines changed

6 files changed

+443
-137
lines changed

src/renderer/src/components/AudioTab/AudioTable.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import Confirm from '../AlertDialog';
1818
import {
1919
findRecord,
2020
PublishDestinationEnum,
21-
useBible,
2221
useOrganizedBy,
2322
usePublishDestination,
2423
} from '../../crud';
@@ -73,7 +72,6 @@ export const AudioTable = (props: IProps) => {
7372
const lang = useSelector((state: IState) => state.strings.lang);
7473
const [offline] = useGlobal('offline'); //verified this is not used in a function 2/18/25
7574
const [memory] = useGlobal('memory');
76-
const [org] = useGlobal('organization');
7775
const [user] = useGlobal('user');
7876
const [offlineOnly] = useGlobal('offlineOnly'); //will be constant here
7977
const [, setBusy] = useGlobal('remoteBusy');
@@ -84,8 +82,6 @@ export const AudioTable = (props: IProps) => {
8482
const [showId, setShowId] = useState('');
8583
const [mediaPlaying, setMediaPlaying] = useState(false);
8684
const [publishItem, setPublishItem] = useState(-1);
87-
const [hasBible, setHasBible] = useState(false);
88-
const { getOrgBible } = useBible();
8985
// const [verHist, setVerHist] = useState('');
9086
const [verValue, setVerValue] = useState<number>();
9187
const { getPublishTo, setPublishTo, isPublished, publishStatus } =
@@ -190,14 +186,6 @@ export const AudioTable = (props: IProps) => {
190186
}
191187
};
192188

193-
useEffect(() => {
194-
if (org) {
195-
const bible = getOrgBible(org);
196-
setHasBible((bible?.attributes.bibleName ?? '') !== '');
197-
}
198-
// eslint-disable-next-line react-hooks/exhaustive-deps
199-
}, [org]);
200-
201189
useEffect(() => {
202190
//if I set playing when I set the mediaId, it plays a bit of the old
203191
if (playItem) setMediaPlaying(true);
@@ -510,10 +498,7 @@ export const AudioTable = (props: IProps) => {
510498
)} */}
511499
{publishItem !== -1 && (
512500
<ConfirmPublishDialog
513-
title={t.publish}
514-
propagateLabel={''}
515-
description={''}
516-
noPropagateDescription={''}
501+
context="media"
517502
yesResponse={publishConfirm}
518503
noResponse={publishRefused}
519504
current={getPublishTo(
@@ -524,7 +509,6 @@ export const AudioTable = (props: IProps) => {
524509
)}
525510
sharedProject={shared}
526511
hasPublishing={hasPublishing}
527-
hasBible={hasBible}
528512
noDefaults={true}
529513
passageType={sortedData[publishItem]?.passageType}
530514
/>

src/renderer/src/components/ConfirmPublishDialog.tsx

Lines changed: 127 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { useMemo, useState } from 'react';
2+
import { useGlobal } from '../context/useGlobal';
23
import {
34
IAlertStrings,
5+
IMediaTabStrings,
6+
IPlanSheetStrings,
47
IPublishLevelStrings,
58
IPublishToStrings,
9+
IPassageTypeStrings,
610
ISharedStrings,
711
} from '../model';
812
import {
@@ -24,25 +28,30 @@ import DialogActions from '@mui/material/DialogActions';
2428
import { shallowEqual, useSelector } from 'react-redux';
2529
import {
2630
alertSelector,
31+
mediaTabSelector,
32+
passageTypeSelector,
33+
planSheetSelector,
2734
publishLevelSelector,
2835
publishToSelector,
2936
sharedSelector,
3037
} from '../selector';
31-
import { PublishLevelEnum, usePublishDestination } from '../crud';
38+
import {
39+
PublishLevelEnum,
40+
useBible,
41+
useOrganizedBy,
42+
usePublishDestination,
43+
} from '../crud';
3244
import ShowLink from '../control/ShowLink';
3345
import { PublishDestinationEnum } from '../crud';
3446
import { PassageTypeEnum } from '../model/passageType';
3547
import { Akuo, Aquifer, ObtHelps } from '../assets/brands';
3648

3749
interface IProps {
38-
title: string;
39-
propagateLabel: string;
40-
description: string;
41-
noPropagateDescription: string;
50+
context: 'plan' | 'media';
51+
isMovement?: boolean;
4252
current: PublishDestinationEnum[];
4353
sharedProject: boolean;
4454
hasPublishing: boolean;
45-
hasBible: boolean;
4655
noDefaults?: boolean;
4756
passageType?: PassageTypeEnum;
4857
noResponse: () => void;
@@ -51,28 +60,48 @@ interface IProps {
5160

5261
function ConfirmPublishDialog(props: IProps) {
5362
const {
54-
title,
55-
propagateLabel,
56-
description,
57-
noPropagateDescription,
63+
context,
64+
isMovement,
5865
sharedProject,
5966
hasPublishing,
60-
hasBible,
6167
yesResponse,
6268
noResponse,
6369
current,
6470
noDefaults,
6571
passageType,
6672
} = props;
6773

68-
const t: IAlertStrings = useSelector(alertSelector, shallowEqual);
69-
const ts: ISharedStrings = useSelector(sharedSelector, shallowEqual);
74+
const alertStrings: IAlertStrings = useSelector(alertSelector, shallowEqual);
75+
const mediaStrings: IMediaTabStrings = useSelector(
76+
mediaTabSelector,
77+
shallowEqual
78+
);
79+
const planSheetStrings: IPlanSheetStrings = useSelector(
80+
planSheetSelector,
81+
shallowEqual
82+
);
83+
const passageTypeStrings: IPassageTypeStrings = useSelector(
84+
passageTypeSelector,
85+
shallowEqual
86+
);
87+
const sharedStrings: ISharedStrings = useSelector(
88+
sharedSelector,
89+
shallowEqual
90+
);
7091
const l: IPublishLevelStrings = useSelector(
7192
publishLevelSelector,
7293
shallowEqual
7394
);
7495
const { getDefaults } = usePublishDestination();
7596
const p: IPublishToStrings = useSelector(publishToSelector, shallowEqual);
97+
const { getOrganizedBy } = useOrganizedBy();
98+
const [org] = useGlobal('organization');
99+
const { getOrgBible } = useBible();
100+
const hasBible = useMemo(() => {
101+
if (!org) return false;
102+
const bible = getOrgBible(org);
103+
return (bible?.attributes.bibleName ?? '') !== '';
104+
}, [getOrgBible, org]);
76105
const [open, setOpen] = useState(true);
77106
const [propagate, setPropagate] = useState(true);
78107
const [value, setValuex] = useState(
@@ -93,6 +122,85 @@ function ConfirmPublishDialog(props: IProps) {
93122
const [akuoValue, setAkuoValue] = useState<PublishLevelEnum>(
94123
calcAkuoValue(value)
95124
);
125+
const usePlanLabels = context === 'plan';
126+
const organizedLabel = getOrganizedBy(true);
127+
const organizedPluralLabel = getOrganizedBy(false);
128+
const isMovementRow = Boolean(isMovement);
129+
const dialogTitle = useMemo(() => {
130+
if (!usePlanLabels) return mediaStrings.publish;
131+
return planSheetStrings.confirmPublish.replace(
132+
'{0}',
133+
isMovementRow ? passageTypeStrings.MOVE : organizedLabel
134+
);
135+
}, [
136+
usePlanLabels,
137+
mediaStrings.publish,
138+
planSheetStrings.confirmPublish,
139+
passageTypeStrings.MOVE,
140+
isMovementRow,
141+
organizedLabel,
142+
]);
143+
const propagateLabel = useMemo(() => {
144+
if (!usePlanLabels) return '';
145+
return planSheetStrings.propagate
146+
.replaceAll(
147+
'{0}',
148+
isMovementRow
149+
? organizedPluralLabel.toLocaleLowerCase()
150+
: sharedStrings.passages.toLocaleLowerCase()
151+
)
152+
.replaceAll(
153+
'{1}',
154+
isMovementRow
155+
? planSheetStrings.movement.toLocaleLowerCase()
156+
: organizedLabel.toLocaleLowerCase()
157+
);
158+
}, [
159+
usePlanLabels,
160+
planSheetStrings.propagate,
161+
planSheetStrings.movement,
162+
sharedStrings.passages,
163+
isMovementRow,
164+
organizedLabel,
165+
organizedPluralLabel,
166+
]);
167+
const description = useMemo(() => {
168+
if (!usePlanLabels) return '';
169+
return isMovementRow
170+
? planSheetStrings.confirmPublishMovement.replaceAll(
171+
'{0}',
172+
organizedPluralLabel.toLocaleLowerCase()
173+
)
174+
: planSheetStrings.confirmPublishSection.replaceAll(
175+
'{0}',
176+
organizedLabel.toLocaleLowerCase()
177+
);
178+
}, [
179+
usePlanLabels,
180+
planSheetStrings.confirmPublishMovement,
181+
planSheetStrings.confirmPublishSection,
182+
isMovementRow,
183+
organizedLabel,
184+
organizedPluralLabel,
185+
]);
186+
const noPropagateDescription = useMemo(() => {
187+
if (!usePlanLabels) return '';
188+
return isMovementRow
189+
? planSheetStrings.confirmPublishMovementNoPropagate
190+
.replaceAll('{0}', organizedPluralLabel.toLocaleLowerCase())
191+
.replaceAll('{1}', Akuo)
192+
: planSheetStrings.confirmPublishSectionNoPropagate.replaceAll(
193+
'{0}',
194+
organizedLabel.toLocaleLowerCase()
195+
);
196+
}, [
197+
usePlanLabels,
198+
planSheetStrings.confirmPublishMovementNoPropagate,
199+
planSheetStrings.confirmPublishSectionNoPropagate,
200+
isMovementRow,
201+
organizedLabel,
202+
organizedPluralLabel,
203+
]);
96204
const setValue = (val: PublishDestinationEnum[]) => {
97205
setValuex(val);
98206
setAkuoValue(calcAkuoValue(val));
@@ -228,7 +336,7 @@ function ConfirmPublishDialog(props: IProps) {
228336
aria-describedby="confirmPublishDesc"
229337
disableEnforceFocus
230338
>
231-
<DialogTitle id="alertDlg">{title}</DialogTitle>
339+
<DialogTitle id="alertDlg">{dialogTitle}</DialogTitle>
232340
<DialogContent>
233341
<DialogContent id="alertJsx">
234342
{hasPublishing && !hasBible && (
@@ -324,7 +432,9 @@ function ConfirmPublishDialog(props: IProps) {
324432
)}
325433
</FormControl>
326434
</DialogContent>
327-
<DialogContentText id="alertDesc">{t.areYouSure}</DialogContentText>
435+
<DialogContentText id="alertDesc">
436+
{alertStrings.areYouSure}
437+
</DialogContentText>
328438
</DialogContent>
329439
<DialogActions>
330440
<Button
@@ -333,7 +443,7 @@ function ConfirmPublishDialog(props: IProps) {
333443
color="primary"
334444
disabled={doingIt}
335445
>
336-
{value === current ? ts.cancel : t.no}
446+
{value === current ? sharedStrings.cancel : alertStrings.no}
337447
</Button>
338448
<Button
339449
id="alertYes"
@@ -343,7 +453,7 @@ function ConfirmPublishDialog(props: IProps) {
343453
disabled={value === current || (!hasBible && needsBibleId) || doingIt}
344454
autoFocus
345455
>
346-
{t.yes}
456+
{alertStrings.yes}
347457
</Button>
348458
</DialogActions>
349459
</Dialog>

0 commit comments

Comments
 (0)