Skip to content

Commit

Permalink
344 current ref resource viewer (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
katherinejensen00 authored Aug 30, 2023
2 parents 827bed9 + 07bf031 commit 60be436
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions extensions/src/resource-viewer/resource-viewer.web-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VerseRef } from '@sillsdev/scripture';
import { VerseRef } from '@sillsdev/scripture';
import papi from 'papi-frontend';
import { RefSelector, ScriptureReference } from 'papi-components';
import { useMemo, useState } from 'react';
import { useMemo } from 'react';
// eslint-disable-next-line import/no-unresolved
import { UsfmProviderDataTypes } from 'usfm-data-provider';
import UsxEditor from 'usxeditor';
Expand Down Expand Up @@ -118,6 +118,12 @@ interface ScriptureTextPanelUsxProps {
usx: string;
}

const defaultScrRef: ScriptureReference = {
bookNum: 1,
chapterNum: 1,
verseNum: 1,
};

/**
* Scripture text panel that displays a read only version of a usx editor that displays the current
* chapter
Expand All @@ -140,21 +146,15 @@ function ScriptureTextPanelUsxEditor({ usx }: ScriptureTextPanelUsxProps) {

const {
react: {
hooks: { useData },
hooks: { useData, useSetting },
},
logger,
} = papi;

const defaultScrRef: ScriptureReference = {
bookNum: 1,
chapterNum: 1,
verseNum: 1,
};

globalThis.webViewComponent = function ResourceViewer() {
logger.info('Preparing to display the Resource Viewer');

const [scrRef, setScrRef] = useState(defaultScrRef);
const [scrRef, setScrRef] = useSetting('platform.verseRef', defaultScrRef);
const [usx, , isLoading] = useData.ChapterUsx<UsfmProviderDataTypes, 'ChapterUsx'>(
'usfm',
useMemo(() => new VerseRef(scrRef.bookNum, scrRef.chapterNum, scrRef.verseNum), [scrRef]),
Expand Down
4 changes: 2 additions & 2 deletions lib/papi-dts/papi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2610,8 +2610,8 @@ declare module 'renderer/hooks/papi-hooks/use-setting.hook' {
*/
const useSetting: <SettingName extends keyof SettingTypes>(
key: SettingName,
defaultState: SettingTypes[SettingName] | null,
) => [SettingTypes[SettingName] | null, (newSetting: SettingTypes[SettingName] | null) => void];
defaultState: SettingTypes[SettingName],
) => [SettingTypes[SettingName], (newSetting: SettingTypes[SettingName]) => void];
export default useSetting;
}
declare module 'renderer/hooks/papi-hooks/index' {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/hooks/papi-hooks/use-setting.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { SettingNames, SettingTypes } from 'papi-shared-types';
*/
const useSetting = <SettingName extends SettingNames>(
key: SettingName,
defaultState: SettingTypes[SettingName] | null,
): [SettingTypes[SettingName] | null, (newSetting: SettingTypes[SettingName] | null) => void] => {
defaultState: SettingTypes[SettingName],
): [SettingTypes[SettingName], (newSetting: SettingTypes[SettingName]) => void] => {
const [setting, setSettingInternal] = useState(() => {
const initialSetting = settingsService.get(key);
return initialSetting !== null ? initialSetting : defaultState;
Expand Down Expand Up @@ -55,9 +55,9 @@ const useSetting = <SettingName extends SettingNames>(
const setSetting = useCallback(
(newSetting: SettingTypes[SettingName] | null) => {
settingsService.set(key, newSetting);
setSettingInternal(newSetting);
setSettingInternal(newSetting !== null ? newSetting : defaultState);
},
[key],
[key, defaultState],
);

return [setting, setSetting];
Expand Down

0 comments on commit 60be436

Please sign in to comment.