Skip to content

Commit

Permalink
Fixed linting errors after web-version (bible-technology#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
samueljd committed Oct 3, 2023
1 parent 56fdfa6 commit 89ca433
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 121 deletions.
33 changes: 8 additions & 25 deletions renderer/src/components/EditorPage/ObsEditor/ObsImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,15 @@ import packageInfo from '../../../../../package.json';
import { newPath } from '../../../../../supabase';

function ObsImage({ story, online }) {
const path = require('path');
const newpath = localStorage.getItem('userPath');
const imageName = story.img.split('/');
const fileName = imageName[imageName.length - 1];
const obsImagePath = isElectron()
? path.join(
'file://',
newpath,
packageInfo.name,
'common',
environment.OBS_IMAGE_DIR,
fileName,
)
: path.join(
newPath,
packageInfo.name,
'common',
environment.OBS_IMAGE_DIR,
fileName,
);
const path = require('path');
const newpath = localStorage.getItem('userPath');
const imageName = story.img.split('/');
const fileName = imageName[imageName.length - 1];
const obsImagePath = isElectron() ? path.join('file://', newpath, packageInfo.name, 'common', environment.OBS_IMAGE_DIR, fileName)
: path.join(newPath, packageInfo.name, 'common', environment.OBS_IMAGE_DIR, fileName);

return online ? (
<img className='w-1/4 rounded-lg' src={story.img} alt='' />
) : (
<img className='w-1/4 rounded-lg' src={obsImagePath} alt='offline' />
);
return online ? (
<img className="w-1/4 rounded-lg" src={story.img} alt="" />) : (<img className="w-1/4 rounded-lg" src={obsImagePath} alt="offline" />);
}

export default ObsImage;
4 changes: 2 additions & 2 deletions renderer/src/components/EditorPage/Scribex/RecursiveBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default function RecursiveBlock({
addSequenceId,
htmlPerf,
onHtmlPerf,
onInput: props?.onInput,
options,
onInput: props?.onInput,
options,
};
component = <HtmlPerfEditor {..._props} />;
}
Expand Down
15 changes: 7 additions & 8 deletions renderer/src/components/EditorPage/Scribex/ReferenceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ export default function ReferenceEditor(props) {
editable,
preview,
},
components: {
block: (__props) =>
ReferenceRecursiveBlock({
htmlPerf,
sequenceIds,
...__props,
}),
},
components: {
block: (__props) => ReferenceRecursiveBlock({
htmlPerf,
sequenceIds,
...__props,
}),
},
decorators: {},
verbose,
handlers,
Expand Down
118 changes: 56 additions & 62 deletions renderer/src/components/EditorPage/Scribex/ReferenceRecursiveBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,71 @@ import React, { useEffect, useState } from 'react';
import { HtmlPerfEditor } from '@xelah/type-perf-html';

const getTarget = ({ content }) => {
const div = document.createElement('div');
div.innerHTML = content;
const div = document.createElement('div');
div.innerHTML = content;

const { target } = div.firstChild?.dataset || {};
const { target } = div.firstChild?.dataset || {};

return target;
return target;
};

export default function ReferenceRecursiveBlock({
htmlPerf,
onHtmlPerf,
sequenceIds,
addSequenceId,
options,
content,
style,
contentEditable,
index,
verbose,
setFootNote,
...props
htmlPerf,
onHtmlPerf,
sequenceIds,
addSequenceId,
options,
content,
style,
contentEditable,
index,
verbose,
setFootNote,
...props
}) {
useEffect(() => {
if (verbose) console.log('Block: Mount/First Render', index);
return () => {
if (verbose) console.log('Block: UnMount/Destroyed', index);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
console.log({ contentEditable });
const checkReturnKeyPress = (event) => {
if (event.key === 'Enter') {
let activeTextArea = document.activeElement;
if (activeTextArea.children.length > 1) {
const lineBreak = activeTextArea.children[1]?.outerHTML;
const newLine = lineBreak.replace(/<br\s*\/?>/gi, '&nbsp');
activeTextArea.children[1].outerHTML = newLine;
}
}
};
const checkReturnKeyPress = (event) => {
if (event.key === 'Enter') {
const activeTextArea = document.activeElement;
if (activeTextArea.children.length > 1) {
const lineBreak = activeTextArea.children[1]?.outerHTML;
const newLine = lineBreak.replace(/<br\s*\/?>/gi, '&nbsp');
activeTextArea.children[1].outerHTML = newLine;
}
}
};

let component;
let component;

let editable = !!content.match(/data-type="paragraph"/);
const editable = !!content.match(/data-type="paragraph"/);

if (editable) {
component = (
<div
contentEditable={contentEditable}
onKeyUp={checkReturnKeyPress}
{...props}
/>
);
}
if (editable) {
component = (
<div
role="textbox"
contentEditable={contentEditable}
onKeyUp={checkReturnKeyPress}
{...props}
tabIndex={0}
/>
);
}

if (!editable) {
const sequenceId = getTarget({ content });
if (!editable) {
const sequenceId = getTarget({ content });

if (sequenceId && !options.preview) {
const _props = {
sequenceIds: [...sequenceIds, sequenceId],
addSequenceId,
htmlPerf,
onHtmlPerf,
onInput: props?.onInput,
options,
};
component = <HtmlPerfEditor {..._props} />;
}
component ||= <div {...props} contentEditable={false} />;
}

return <>{component}</>;
if (sequenceId && !options.preview) {
const _props = {
sequenceIds: [...sequenceIds, sequenceId],
addSequenceId,
htmlPerf,
onHtmlPerf,
onInput: props?.onInput,
options,
};
component = <HtmlPerfEditor {..._props} />;
}
component ||= <div {...props} contentEditable={false} />;
}
// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{component}</>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const checkandDownloadObsImages = async () => {
const obsImagePath = `${packageInfo.name}/common/${environment.OBS_IMAGE_DIR}`;
const { data: exist } = await sbStorageList(obsImagePath);
if (!exist) {
await createDirectory({path:obsImagePath});
await createDirectory({ path: obsImagePath });
}
const { data: filesInDir } = await sbStorageDownload(obsImagePath);
console.log({ filesInDir });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ const DownloadCreateSBforHelps = async (projectResource, setLoading, update = fa
const { data: folderExist } = await sbStorageList(folder);
console.log({ folderExist });
if (!folderExist) {
await createDirectory({path:folder});
await createDirectory({ path: folder });
}
// writing zip to local
await createDirectory({path:`${folder}/${projectResource?.name}.zip}`,payload: Buffer.from(blob)});
await createDirectory({ path: `${folder}/${projectResource?.name}.zip}`, payload: Buffer.from(blob) });

// extract zip
const { data: filecontent, error: fileContentError } = await sbStorageDownload(`${folder}/${projectResource?.name}.zip}`);
Expand All @@ -170,18 +170,18 @@ const DownloadCreateSBforHelps = async (projectResource, setLoading, update = fa
for (const key of keys) {
const item = result.files[key];
if (item.dir) {
await createDirectory({path:`${folder}/${item.name}`});
await createDirectory({ path: `${folder}/${item.name}` });
} else {
const bufferContent = Buffer.from(await item.async('arraybuffer'));
await createDirectory({path:`${folder}/${item.name}`,payload: bufferContent});
await createDirectory({ path: `${folder}/${item.name}`, payload: bufferContent });
}
}

await fetch(projectResource.metadata_json_url).then((res) => res.json()).then(async (data) => {
data.agOffline = true;
data.meta = projectResource;
data.lastUpdatedAg = moment().format();
await createDirectory({path:`${folder}/${projectResource?.name}/metadata.json`, payload :JSON.stringify(data)});
await createDirectory({ path: `${folder}/${projectResource?.name}/metadata.json`, payload: JSON.stringify(data) });
}).catch((err) => {
console.log('DownloadCreateSBforHelps.js', 'failed to save yml metadata.json : ', err);
});
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/Resources/useReadLocalResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function readLocalResources(username, setSubMenuItems) {
const parseData = [];
const projectsDir = `${newPath}/${email}/resources`;
const userResourceMetaPath = `${newPath}/${email}/resources`;
createDirectory({path:userResourceMetaPath});
createDirectory({ path: userResourceMetaPath });
readResourceMetadata(projectsDir, userResourceMetaPath, setSubMenuItems, parseData);
}
}
2 changes: 1 addition & 1 deletion renderer/src/core/Login/handleJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const handleJsonWeb = async (values) => {
});

console.log('handleJson.js', 'Successfully added new user to the existing list in file', { newUser });
await createDirectory({path:`${newpath}/${values.email}/projects`});
await createDirectory({ path: `${newpath}/${values.email}/projects` });

console.log('handleJson.js', 'Successfully created directories for new user');
// Add new user to localForage:
Expand Down
30 changes: 15 additions & 15 deletions renderer/src/core/editor/writeToFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ const writeToFile = async ({
username, projectname, filename, data,
});
if (!IsElectron) {
const filePath = `${newPath}/${username}/projects/${projectname}/${filename}`;
const { data: projectsPath, error } = await sbStorageDownload(filePath);
if (projectsPath) {
// appending to an existing file
console.log('writeToFile.js', 'Appending to the existing file');
sbStorageUpdate({ path: filePath, payload: data });
} else {
// Creating new file if nothing present
console.log('writeToFile.js', 'Creating new file to write');
sbStorageUpload(filePath, data);
}
if (error) {
console.log(error);
}
}
const filePath = `${newPath}/${username}/projects/${projectname}/${filename}`;
const { data: projectsPath, error } = await sbStorageDownload(filePath);
if (projectsPath) {
// appending to an existing file
console.log('writeToFile.js', 'Appending to the existing file');
sbStorageUpdate({ path: filePath, payload: data });
} else {
// Creating new file if nothing present
console.log('writeToFile.js', 'Creating new file to write');
sbStorageUpload(filePath, data);
}
if (error) {
console.log(error);
}
}
};

export default writeToFile;
2 changes: 1 addition & 1 deletion renderer/src/core/projects/saveProjetcsMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const saveSupabaseProjectsMeta = async (projectMetaObj) => {
const userProfile = await localforage.getItem('userProfile');
const currentUser = userProfile.user.email;
const status = [];
await createDirectory({path:`${newPath}/${currentUser}/projects`});
await createDirectory({ path: `${newPath}/${currentUser}/projects` });
const projectDir = `${newPath}/${currentUser}/projects}`;
let projectNameExists = false;
let checkCanon = false;
Expand Down

0 comments on commit 89ca433

Please sign in to comment.