Skip to content

Commit

Permalink
Merge pull request #733 from friendsofagape/Resource-Fix1
Browse files Browse the repository at this point in the history
Updating resource loading code with lint fix
  • Loading branch information
vipinpaul authored Dec 21, 2022
2 parents 23b695c + 5879076 commit b1c9957
Show file tree
Hide file tree
Showing 24 changed files with 17,761 additions and 16,796 deletions.
150 changes: 61 additions & 89 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions renderer/src/components/EditorPage/Scribex/Buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ export default function Buttons(props) {
return (
<>
<RectangleStackIcon
aria-label='Collection-Icon'
aria-label="Collection-Icon"
className={classNames(
sectionable ? 'fill-current' : '',
'h-5 mr-2 w-5 text-white cursor-pointer',
)}
aria-hidden='true'
aria-hidden="true"
onClick={onSectionable}
/>

<PencilIcon
aria-label='Collection-Icon'
aria-label="Collection-Icon"
className={classNames(
editable ? 'fill-current' : '',
'h-5 mr-2 w-5 text-white cursor-pointer',
)}
aria-hidden='true'
aria-hidden="true"
onClick={onEditable}
/>

Expand Down
10 changes: 4 additions & 6 deletions renderer/src/components/Resources/ImportResource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {
useRef, Fragment, useContext, useState,
Fragment, useContext, useState,
} from 'react';
import PropTypes from 'prop-types';

Expand All @@ -13,9 +13,8 @@ import * as logger from '../../logger';
import { viewBurrito } from '../../core/burrito/importBurrito';

export default function ImportResource({
open, closePopUp, setOpenResourcePopUp, setLoading,
closePopUp, setOpenResourcePopUp, setLoading,
}) {
const cancelButtonRef = useRef(null);
const [valid, setValid] = useState(false);
const [snackBar, setOpenSnackBar] = useState(false);
const [snackText, setSnackText] = useState('');
Expand Down Expand Up @@ -66,7 +65,7 @@ export default function ImportResource({
logger.debug('ImportResource.js', 'error in uploading resource to specified location');
setNotify(err);
});
setFolderPath('')
setFolderPath('');
};
const uploadRefBible = async () => {
const fs = window.require('fs');
Expand Down Expand Up @@ -127,7 +126,7 @@ export default function ImportResource({
name="location"
id=""
value={folderPath}
onChange={(e) => c(e.target.value)}
onChange={(e) => setFolderPath(e.target.value)}
className="bg-white w-52 lg:w-80 block rounded shadow-sm sm:text-sm focus:border-primary border-gray-300"
/>
<button
Expand Down Expand Up @@ -172,7 +171,6 @@ export default function ImportResource({
}

ImportResource.propTypes = {
open: PropTypes.bool,
closePopUp: PropTypes.func,
setOpenResourcePopUp: PropTypes.func,
setLoading: PropTypes.func,
Expand Down
23 changes: 13 additions & 10 deletions renderer/src/components/Resources/ListResources.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable jsx-a11y/control-has-associated-label */
import {
useEffect, useState, useContext,
} from 'react';
Expand All @@ -6,7 +8,6 @@ import CheckHelpsUpdatePopUp from '@/components/Resources/ResourceUtils/CheckHel
import RemoveResource from '@/components/Resources/ResourceUtils/RemoveResource';
import { ArrowDownTrayIcon } from '@heroicons/react/24/solid';
import { ProjectContext } from '@/components/context/ProjectContext';
import { readResourceMetadata } from '@/components/Resources/ResourceUtils/readResourceMetadata';
import * as logger from '../../logger';
import LoadingScreen from '../Loading/LoadingScreen';

Expand Down Expand Up @@ -52,18 +53,16 @@ export const ListResources = ({
createData('Spanish', 'es-419', 'es-419_gl'),
];


const { t } = useTranslation();
const [offlineResources, setOfflineResources] = useState([]);
const [onlineResources, setOnlineResources] = useState();
// eslint-disable-next-line no-unused-vars
const [translationWordList, settranslationWordList] = useState(translationWordLists);
const [translationNote, setTranslationNote] = useState([]);
const [translationQuestion, setTranslationQuestion] = useState([]);
const [translationWord, settranslationWord] = useState([]);
const [translationAcademy, setTranslationAcademy] = useState([]);
const [obsTranslationNote, setObsTranslationNote] = useState([]);
const [obsTranslationQuestion, setObsTranslationQuestion] = useState([]);

const [renderApp, setRenderApp] = useState(false);
const handleDownloadHelpsResources = async (event, reference, offlineResource) => {
if (!downloading) {
try {
Expand All @@ -73,6 +72,7 @@ export const ListResources = ({
setCurrentDownloading(null);
setOpenSnackBar(true);
setError('success');
setRenderApp(true);
setSnackText('Resource Download Finished');
} catch (err) {
logger.debug('ResourcesPopUp.js', 'Error Downlaod ', err);
Expand All @@ -89,7 +89,7 @@ export const ListResources = ({

useEffect(() => {
(async () => {
setLoading(true)
setLoading(true);
logger.debug('ResourcesPopUp.js', `get available selected resources ${selectResource}`);
switch (selectResource) {
case 'tn':
Expand All @@ -113,7 +113,7 @@ export const ListResources = ({
default:
break;
}
setLoading(false)
setLoading(false);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectResource, selectedPreProd]);
Expand All @@ -139,8 +139,10 @@ export const ListResources = ({

useEffect(() => { // LOADS locally available
readLocalResources(username, setSubMenuItems);
}, []);
console.log(">>>>>>>>>>>>>>>>>>>>>",filteredResources?.onlineResource)
if (renderApp === true) {
setRenderApp(false);
}
}, [renderApp]);

return (
<div className="h-full">
Expand Down Expand Up @@ -231,6 +233,7 @@ export const ListResources = ({
<RemoveResource
resource={resource}
selectResource={selectResource}
setRenderApp={setRenderApp}
/>
</div>
</div>
Expand Down Expand Up @@ -323,4 +326,4 @@ export const ListResources = ({
)}
</div>
);
};
};
25 changes: 18 additions & 7 deletions renderer/src/components/Resources/ObsBibleAudioTab.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import React, { useContext, useEffect,useReducer } from 'react';
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable no-nested-ternary */
/* eslint-disable jsx-a11y/control-has-associated-label */
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import RemoveResource from '@/components/Resources/ResourceUtils/RemoveResource';
import CheckHelpsUpdatePopUp from '@/components/Resources/ResourceUtils/CheckHelpsUpdatePopUp';
import { ProjectContext } from '@/components/context/ProjectContext';
import readLocalResources from './useReadLocalResources';
import LoadingScreen from '../Loading/LoadingScreen';

export default function ObsBibleAudioTab({
selectResource,
filteredBibleObsAudio,
removeSection,
handleRowSelect,
setfilteredBibleObsAudio,
loading,
setSubMenuItems,
subMenuItems,
}) {
const { t } = useTranslation();
const [renderApp, setRenderApp] = useState(false);
const {
states: {
username,
Expand All @@ -26,11 +30,14 @@ export default function ObsBibleAudioTab({
{ resourceType: 'obs', flavorName: 'textStories' },
{ resourceType: 'audio', flavorName: 'audioTranslation' },
];
const currentResourceType = resourceMap.find((resourceItem) => resourceItem.resourceType == selectResource);
const currentResourceType = resourceMap.find((resourceItem) => resourceItem.resourceType === selectResource);

useEffect(() => { // LOADS locally available
readLocalResources(username, setSubMenuItems);
}, []);
if (renderApp === true) {
setRenderApp(false);
}
}, [renderApp]);

useEffect(() => {
const resourceName = (selectResource === 'bible')
Expand Down Expand Up @@ -151,10 +158,14 @@ export default function ObsBibleAudioTab({
&& (
<CheckHelpsUpdatePopUp resource={ref} selectResource={selectResource} />
)}
{selectResource !== 'audio' &&
<RemoveResource resource={ref}
{selectResource !== 'audio'
&& (
<RemoveResource
resource={ref}
selectResource={selectResource}
/>}
setRenderApp={setRenderApp}
/>
)}
</div>
</div>
</td>
Expand Down
3 changes: 1 addition & 2 deletions renderer/src/components/Resources/ResourceTabPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default function ResourceTabPane({
}) {
const [isOpenDonwloadPopUp, setIsOpenDonwloadPopUp] = useState(false);
const [resourceIconClick, setResourceIconClick] = useState(false);
console.log({ selectResource });
const openResourceDialogBox = () => {
if (selectResource === 'bible' || selectResource === 'obs') {
logger.debug('DownloadResourcePopUp.js', 'Calling bible resource pop up');
Expand All @@ -46,7 +45,7 @@ export default function ResourceTabPane({
>
{selectResource}
</Tab>
{selectResource != 'audio'
{selectResource !== 'audio'
&& (
<Tab as={Fragment}>
{({ selected }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function CustomMultiComboBox({
}) {
let filteredData = [];
const [query, setQuery] = useState('');
// eslint-disable-next-line no-unused-vars
const [isActive, setIsActive] = useState(false);
if (customData.length === 1) {
setSelectedList(customData);
Expand All @@ -23,7 +24,7 @@ function CustomMultiComboBox({
customData.length > 1 ? (
<Combobox value={selectedList} onChange={setSelectedList} multiple>
{({ open }) => (
<div className="relative">
<div className="relative">
<div className="relative w-full border border-gray-200 cursor-default overflow-hidden rounded-lg bg-white text-left shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-opacity-75 focus-visible:ring-offset-2 focus-visible:ring-offset-teal-300 sm:text-sm">

<Combobox.Input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable react/no-array-index-key */
/* eslint-disable jsx-a11y/control-has-associated-label */
/* eslint-disable no-unused-vars */
/* eslint-disable react/jsx-key */
/* eslint-disable no-nested-ternary */
import React, { useEffect, useState } from 'react';
Expand All @@ -11,10 +14,10 @@ import { makeStyles } from '@material-ui/core/styles';
import LoadingScreen from '@/components/Loading/LoadingScreen';
import { XMarkIcon, ArrowDownTrayIcon } from '@heroicons/react/24/solid';
import { AutographaContext } from '@/components/context/AutographaContext';
import { TrashIcon } from '@heroicons/react/24/outline';
import CustomMultiComboBox from './CustomMultiComboBox';
import langJson from '../../../lib/lang/langNames.json';
import { handleDownloadResources } from './createDownloadedResourceSB';
import { TrashIcon } from '@heroicons/react/24/outline';
import * as logger from '../../../logger';

const subjectTypeArray = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const ResourceResetAfterCheckSameOnRefResourceAgSettings = async (setResetResour
};

function RemoveResource({
resource, selectResource,
resource, selectResource, setRenderApp,
}) {
logger.warn('removeResource.js', 'inside remove resource');
const { t } = useTranslation();
Expand Down Expand Up @@ -148,6 +148,7 @@ function RemoveResource({
// read ag-settings of the project
await ResourceResetAfterCheckSameOnRefResourceAgSettings(setResetResourceOnDeleteOffline, resource);
// handleRowSelect(null, null, null, null, '');
setRenderApp(true);
setOpenSnackBar(true);
setNotify('success');
setSnackText('Removed Resource Successfully');
Expand Down Expand Up @@ -193,7 +194,7 @@ function RemoveResource({
RemoveResource.propTypes = {
resource: PropTypes.object,
selectResource: PropTypes.string,
closeResourceWindow: PropTypes.func,
setRenderApp: PropTypes.func,
};

export default RemoveResource;
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { readRefMeta } from '@/core/reference/readRefMeta';
import { readRefBurrito } from '@/core/reference/readRefBurrito';
import * as localforage from 'localforage';

const path = require('path');

export async function readResourceMetadata(projectsDir, resourcePath, setSubMenuItems, parseData) {
const refs = await readRefMeta({ projectsDir });
refs.forEach(async (ref) => {
const metaPath = path.join(`${resourcePath}` , ref, 'metadata.json')
const data = await readRefBurrito({ metaPath })
const metaPath = path.join(`${resourcePath}`, ref, 'metadata.json');
const data = await readRefBurrito({ metaPath });
if (data) {
const burrito = {};
burrito.projectDir = ref;
Expand Down
12 changes: 7 additions & 5 deletions renderer/src/components/Resources/ResourcesPopUp.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React, { useRef, useState, useContext, Fragment } from 'react';
/* eslint-disable no-unused-vars */
import React, {
useRef, useState, useContext, Fragment,
} from 'react';
import { XMarkIcon } from '@heroicons/react/24/solid';
import ResourcesSidebar from '@/components/Resources/ResourcesSideBar';
import { ReferenceContext } from '@/components/context/ReferenceContext';
import ResourceTabPane from '@/components/Resources/ResourceTabPane';
import { useTranslation } from 'react-i18next';
import { Dialog, Transition } from '@headlessui/react';
import { ListResources } from '@/components/Resources/ListResources';
import * as logger from '../../logger';
import { SnackBar } from '@/components/SnackBar';
import SearchBar from '@/components/Resources/SearchBar';
import * as logger from '../../logger';

export default function ResourcesPopUp(
{
Expand Down Expand Up @@ -96,8 +99,7 @@ export default function ResourcesPopUp(
<div className="flex flex-col mx-12 mt-10 fixed inset-0 z-10 overflow-y-auto">
<div className="bg-black relative flex justify-between px-3 items-center rounded-t-lg h-10 ">
<h1 className="text-white font-bold text-sm">RESOURCES</h1>
<div aria-label="resources-search" className="pt-1.5 pb-[6.5px] bg-secondary text-white text-xs tracking-widest leading-snug text-center">
</div>
<div aria-label="resources-search" className="pt-1.5 pb-[6.5px] bg-secondary text-white text-xs tracking-widest leading-snug text-center" />
<button
type="button"
className="bg-primary absolute h-full rounded-tr-lg right-0 text-white"
Expand All @@ -109,7 +111,7 @@ export default function ResourcesPopUp(
</div>
<div className="flex border bg-white">
<ResourcesSidebar selectResource={selectResource} setSelectResource={setSelectResource} setShowInput={setShowInput} setTitle={setTitle} />
<div className="h-[85vh] w-full overflow-x-scroll bg-gray-50 items-center p-3 justify-between" >
<div className="h-[85vh] w-full overflow-x-scroll bg-gray-50 items-center p-3 justify-between">
<SearchBar
currentFullResources={currentFullResources}
selectResource={selectResource}
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/components/Resources/ResourcesSideBar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react/no-array-index-key */
/* eslint-disable no-unused-vars */
import {
DocumentTextIcon,
PhotoIcon,
Expand All @@ -21,8 +23,6 @@ export default function ResourcesSidebar({
const { t } = useTranslation();

const handleClick = (id) => {
console.log('handle click');
console.log(id);
setSelectResource(id);
};
useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions renderer/src/components/Resources/ResourcesSideBarOption.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-unused-vars */
/* eslint-disable react/no-unused-prop-types */
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { classNames } from '@/util/classNames';
Expand Down
Loading

0 comments on commit b1c9957

Please sign in to comment.