Skip to content

Commit

Permalink
changing the useStateCard for displaying the items
Browse files Browse the repository at this point in the history
  • Loading branch information
vipinpaul committed Nov 24, 2023
1 parent c03ab31 commit 534cb33
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 64 deletions.
50 changes: 31 additions & 19 deletions renderer/src/components/EditorPage/Reference/ReferenceCard.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';

import { CardContent } from 'translation-helps-rcl';
import { CardContent, useCardState } from 'translation-helps-rcl';
import TranslationhelpsNav from './TranslationhelpsNav';

const ReferenceCard = ({
items,
item,
filters,
markdownView,
markdown,
languageId,
selectedQuote,
Expand All @@ -16,23 +14,39 @@ const ReferenceCard = ({
isLoading,
font,
}) => {
const {
state: {
item, itemIndex, markdownView,
},
actions: {
setItemIndex,
},
} = useCardState({ items });
console.log({ item });

Check warning on line 25 in renderer/src/components/EditorPage/Reference/ReferenceCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 25 in renderer/src/components/EditorPage/Reference/ReferenceCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

console.log('testing');

Check warning on line 26 in renderer/src/components/EditorPage/Reference/ReferenceCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 26 in renderer/src/components/EditorPage/Reference/ReferenceCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
return (
<div style={{ fontFamily: font || 'sans-serif' }}>
<CardContent
item={item}
<>
<TranslationhelpsNav
classes
items={items}
filters={filters}
markdown={markdown}
languageId={languageId}
markdownView={markdownView}
isLoading={isLoading}
selectedQuote={selectedQuote}
setQuote={setQuote}
viewMode={viewMode}
itemIndex={itemIndex}
setItemIndex={setItemIndex}
/>
</div>
<div style={{ fontFamily: font || 'sans-serif' }}>
<CardContent
item={item}
items={items}
filters={filters}
markdown={markdown}
languageId={languageId}
markdownView={markdownView}
isLoading={isLoading}
selectedQuote={selectedQuote}
setQuote={setQuote}
viewMode={viewMode}
/>
</div>
</>

);
};
Expand All @@ -41,9 +55,7 @@ export default ReferenceCard;

ReferenceCard.propTypes = {
items: PropTypes.array,
item: PropTypes.object,
filters: PropTypes.array,
markdownView: PropTypes.bool,
markdown: PropTypes.object,
languageId: PropTypes.string.isRequired,
selectedQuote: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import PropTypes from 'prop-types';
import { useEffect, useState } from 'react';
import {
useContent,
useCardState,
// useCardState,
// CardContent,
} from 'translation-helps-rcl';
import localForage from 'localforage';
import ReferenceCard from './ReferenceCard';
import TranslationhelpsNav from './TranslationhelpsNav';
// import TranslationhelpsNav from './TranslationhelpsNav';
import * as logger from '../../../logger';
import packageInfo from '../../../../../package.json';

Expand Down Expand Up @@ -45,15 +46,6 @@ export default function TranslationHelpsCard({
readyToFetch: true,
});

const {
state: {
item, headers, fontSize, itemIndex, markdownView,
},
actions: {
setFilters, setFontSize, setItemIndex, setMarkdownView,
},
} = useCardState({ items });

useEffect(() => {
if (offlineResource && offlineResource.offline) {
// console.log('offline in Helpscard : ', offlineResource);
Expand All @@ -69,22 +61,27 @@ export default function TranslationHelpsCard({
const currentUser = user?.username;
const folder = path.join(newpath, packageInfo.name, 'users', `${currentUser}`, 'resources');
const projectName = `${offlineResource?.data?.value?.meta?.name}_${offlineResource?.data?.value?.meta?.owner}_${offlineResource?.data?.value?.meta?.release?.tag_name}`;

// const projectName = 'en_tn_unfoldingWord_v77 (copy)';
console.log(resourceId);

Check warning on line 65 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 65 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
// switch resources
switch (resourceId) {
case 'tn':
console.log(path.join(folder, projectName), fs.existsSync(path.join(folder, projectName)));

Check warning on line 69 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 69 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
if (fs.existsSync(path.join(folder, projectName))) {
console.log('yes');

Check warning on line 71 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 71 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
// eslint-disable-next-line array-callback-return
const currentFile = offlineResource?.data?.value?.projects.filter((item) => {
console.log('item', item, projectId);

Check warning on line 74 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 74 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
if (item?.identifier.toLowerCase() === projectId.toLowerCase()) {
return item;
}
});
// console.log('project name content : ', currentFile[0].path);
console.log('project name content : ', currentFile[0].path);

Check warning on line 79 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 79 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
const filecontent = await fs.readFileSync(path.join(folder, projectName, currentFile[0].path), 'utf8');
console.log(filecontent);

Check warning on line 81 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 81 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
// convert tsv to json
const headerArr = filecontent.split('\n')[0].split('\t');

console.log(headerArr);

Check warning on line 84 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 84 in renderer/src/components/EditorPage/Reference/TranslationHelpsCard.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
let noteName;
let indexOfNote;
if (headerArr.indexOf('Note') > 0) {
Expand Down Expand Up @@ -214,45 +211,27 @@ export default function TranslationHelpsCard({
}
}
// reset index
setItemIndex(0);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [verse, chapter, languageId, resourceId, owner, offlineResource, projectId, items, filePath]);

items = !offlineItemsDisable && offlineResource?.offline ? offlineItems : items;
markdown = offlineResource?.offline ? offlineMarkdown : markdown;

console.log('==========> ', !offlineItemsDisable && offlineResource?.offline, { items, item, markdown });
console.log('==========> ', !offlineItemsDisable && offlineResource?.offline, { items, markdown });

return (
<>
<TranslationhelpsNav
classes
items={items}
itemIndex={itemIndex}
setItemIndex={setItemIndex}
/>
<ReferenceCard
items={items}
headers={headers}
filters={['OccurrenceNote', 'Question', 'Response']}
fontSize={fontSize}
itemIndex={itemIndex}
setFilters={setFilters}
setFontSize={setFontSize}
setItemIndex={setItemIndex}
markdownView={markdownView}
setMarkdownView={setMarkdownView}
item={item}
markdown={markdown}
isLoading={isLoading}
languageId={languageId}
title={title}
viewMode={viewMode}
selectedQuote={selectedQuote}
setQuote={setQuote}
font={font}
/>
</>
<ReferenceCard
items={items}
filters={['OccurrenceNote', 'Question', 'Response']}
markdown={markdown}
isLoading={isLoading}
languageId={languageId}
title={title}
viewMode={viewMode}
selectedQuote={selectedQuote}
setQuote={setQuote}
font={font}
/>
);
}

Expand Down

0 comments on commit 534cb33

Please sign in to comment.