Skip to content

Commit

Permalink
save font size and reload. Editor font size is resetting some times.
Browse files Browse the repository at this point in the history
  • Loading branch information
sijumoncy committed May 29, 2024
1 parent 5fb4cb6 commit 7628e08
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 14 deletions.
7 changes: 6 additions & 1 deletion renderer/src/components/EditorPage/ObsEditor/ObsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { getDetails } from './utils/getDetails';
const ObsEditor = () => {
const [mdData, setMdData] = useState();
const [directoryName, setDirectoryName] = useState();
const { state: { obsNavigation, loadData }, actions: { setLoadData } } = useContext(ReferenceContext);
const {
state: {
obsNavigation, loadData,
}, actions: { setLoadData },
} = useContext(ReferenceContext);

const updateStory = (story) => {
logger.debug('ObsEditor.js', 'In updateStory for upadting the story to the backend md file');
Expand Down Expand Up @@ -89,6 +93,7 @@ const ObsEditor = () => {
);
localforage.setItem('projectmeta', value);
// This func will update the scribe-setting.json file
// saveReferenceResource(selectedFont, editorFontSize);
saveReferenceResource();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function EditorMenuBar(props) {
setVerseNumber,
handleSelectedFont,
setTriggerVerseInsert,
setEditorFontSize,
handleEditorFontSize,
editorFontSize,
} = props;

Expand All @@ -31,10 +31,10 @@ export default function EditorMenuBar(props) {

const handleFontSize = (status) => {
if (status === 'dec' && editorFontSize > 0.70) {
setEditorFontSize(editorFontSize - 0.2);
handleEditorFontSize(editorFontSize - 0.2);
}
if (status === 'inc' && editorFontSize < 2) {
setEditorFontSize(editorFontSize + 0.2);
handleEditorFontSize(editorFontSize + 0.2);
}
};

Expand Down
4 changes: 2 additions & 2 deletions renderer/src/components/EditorPage/TextEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function TextEditor() {
const {
state: { bookId, selectedFont, editorFontSize },
actions: {
handleSelectedFont, onChangeChapter, onChangeVerse, setEditorFontSize,
handleSelectedFont, onChangeChapter, onChangeVerse, handleEditorFontSize,
},
} = useContext(ReferenceContext);

Expand Down Expand Up @@ -104,7 +104,7 @@ export default function TextEditor() {
bookName,
bookChange,
bookAvailable,
setEditorFontSize,
handleEditorFontSize,
setBookChange,
setChapterNumber,
setVerseNumber,
Expand Down
5 changes: 5 additions & 0 deletions renderer/src/components/Sync/Gitea/SyncFromGiteaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ async function createOrUpdateAgSettings(sbDataObject, currentUser, projectName,
} else {
setting.project[sbDataObject.type.flavorType.flavor.name].font = (setting.project[sbDataObject.type.flavorType.flavor.name].font) ? (setting.project[sbDataObject.type.flavorType.flavor.name].font) : '';
}
if (!setting.fontSize) {
setting.project[sbDataObject.type.flavorType.flavor.name].fontSize = 1;
} else {
setting.project[sbDataObject.type.flavorType.flavor.name].fontSize = (setting.project[sbDataObject.type.flavorType.flavor.name].fontSize) ? (setting.project[sbDataObject.type.flavorType.flavor.name].fontSize) : 1;
}
settings = setting;
}
settings.project[sbDataObject.type.flavorType.flavor.name].lastSeen = moment().format();
Expand Down
13 changes: 13 additions & 0 deletions renderer/src/components/context/ReferenceContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ export default function ReferenceContextProvider({ children }) {
}
};

// define functon to change editor font size and call saveReference
const handleEditorFontSize = async (currentFontSize) => {
if (isElectron()) {
setEditorFontSize(currentFontSize);
// INFO : implement a debounce for this call if needed
saveReferenceResource(selectedFont, currentFontSize);
}
};

useEffect(() => {
localforage.getItem('currentProject').then(async (projectName) => {
if (projectName) {
Expand All @@ -112,17 +121,20 @@ export default function ReferenceContextProvider({ children }) {
setBookmarksVerses(resources.project?.textTranslation.bookMarks);
setProjectScriptureDir(resources.project?.textTranslation?.scriptDirection?.toUpperCase());
setSelectedFont(resources.project?.textTranslation?.font);
setEditorFontSize(resources.project?.textTranslation?.fontSize || 1);
break;
case 'textStories':
setBookmarksVerses(resources.project?.textStories.bookMarks);
setProjectScriptureDir(resources.project?.textStories?.scriptDirection?.toUpperCase());
setObsNavigation(resources.project?.textStories.navigation ? resources.project?.textStories.navigation : '1');
setSelectedFont(resources.project?.textStories?.font);
setEditorFontSize(resources.project?.textStories?.fontSize);
break;
case 'audioTranslation':
setBookmarksVerses(resources.project?.audioTranslation.bookMarks);
setProjectScriptureDir(resources.project?.audioTranslation?.scriptDirection?.toUpperCase());
setSelectedFont(resources.project?.audioTranslation?.font);
setEditorFontSize(resources.project?.audioTranslation?.fontSize || 1);
break;
default:
break;
Expand Down Expand Up @@ -237,6 +249,7 @@ export default function ReferenceContextProvider({ children }) {
onChangeChapter,
onChangeVerse,
applyBooksFilter,
handleEditorFontSize,
setAnchorEl,
handleClick,
setRefName,
Expand Down
5 changes: 5 additions & 0 deletions renderer/src/core/burrito/importBurrito.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ const importBurrito = async (filePath, currentUser, updateBurritoVersion, concat
} else {
setting.font = (setting.project[metadata.type.flavorType.flavor.name].font) ? (setting.project[metadata.type.flavorType.flavor.name].font) : '';
}
if (!setting.project[metadata.type.flavorType.flavor.name]?.fontSize) {
setting.project[metadata.type.flavorType.flavor.name].fontSize = 1;
} else {
setting.fontSize = (setting.project[metadata.type.flavorType.flavor.name]?.fontSize) ? (setting.project[metadata.type.flavorType.flavor.name].fontSize) : 1;
}
settings = setting;
}
settings.project[metadata.type.flavorType.flavor.name].lastSeen = moment().format();
Expand Down
4 changes: 4 additions & 0 deletions renderer/src/core/editor/fetchSettingsResourceHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function fetchSettingsResourceHistory(
owner: '',
offlineResource: { offline: false },
font: '',
fontSize: 1,
}
));
} else if (_columnnum === historyColumn && _rownum === '2') {
Expand All @@ -134,6 +135,7 @@ export async function fetchSettingsResourceHistory(
owner: '',
offlineResource: { offline: false },
font: '',
fontSize: 1,
}
));
}
Expand All @@ -158,6 +160,7 @@ export async function fetchSettingsResourceHistory(
owner: _value?.owner,
offlineResource: _value?.offline,
font: _value?.font,
fontSize: _value?.fontSize || 1,
});
}
if (_rownum === '2') {
Expand All @@ -170,6 +173,7 @@ export async function fetchSettingsResourceHistory(
owner: _value?.owner,
offlineResource: _value?.offline,
font: _value?.font,
fontSize: _value?.fontSize || 1,
});
}
},
Expand Down
9 changes: 8 additions & 1 deletion renderer/src/core/editor/saveSettingsResourceHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export async function saveSettingsResourceHistory(
setReferenceColumnData2,
setOpenResourceR1,
setOpenResourceR2,
selectedFont,
editorFontSize,
) {
logger.debug('SaveSettingsResourceHistory.js', 'In save reference hsotory func');
// removingSection : "1" and openResourceR2 :false and sectionPlaceholderNum: "1" -> reference 2 to reference 1
Expand Down Expand Up @@ -70,6 +72,7 @@ export async function saveSettingsResourceHistory(
owner: referenceColumnData2?.owner,
offlineResource: referenceColumnData2.offlineResource,
font: referenceColumnData2?.font,
fontSize: referenceColumnData2?.fontSize || 1,
}
));
setReferenceColumnData2((prev) => ({
Expand All @@ -81,6 +84,7 @@ export async function saveSettingsResourceHistory(
owner: '',
offlineResource: { offline: false },
font: '',
fontSize: 1,
}
));
setOpenResourceR1(false);
Expand All @@ -95,6 +99,7 @@ export async function saveSettingsResourceHistory(
navigation: { book: '1TI', chapter: '1' },
offline: referenceToUse.offlineResource,
font: referenceToUse?.font,
fontSize: referenceToUse?.fontSize || 1,
},
};
}
Expand All @@ -111,6 +116,7 @@ export async function saveSettingsResourceHistory(
navigation: { book: '1TI', chapter: '1' },
offline: referenceColumnData1.offlineResource,
font: referenceColumnData1?.font,
fontSize: referenceColumnData1?.fontSize || 1,
},
2: {
resouceId: referenceColumnData2?.selectedResource,
Expand All @@ -120,6 +126,7 @@ export async function saveSettingsResourceHistory(
navigation: { book: '1TI', chapter: '1' },
offline: referenceColumnData2.offlineResource,
font: referenceColumnData2?.font,
fontSize: referenceColumnData2?.fontSize || 1,
},
};
}
Expand All @@ -139,7 +146,7 @@ export async function saveSettingsResourceHistory(
setRemovingSection();
setAddingSection();
localforage.setItem('projectmeta', value).then(() => {
saveReferenceResource();
saveReferenceResource(selectedFont, editorFontSize);
resolve();
});
}
Expand Down
16 changes: 13 additions & 3 deletions renderer/src/core/projects/updateAgSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
// const newPath = require('../../../../supabase').newPath
// }

export const updateAgSettings = async (username, projectName, data, font) => {
export const updateAgSettings = async (username, projectName, data, font, fontSize = 1) => {
logger.debug('updateAgSettings.js', 'In updateAgSettings');
const newpath = localStorage.getItem('userPath');
const fs = window.require('fs');
Expand All @@ -31,10 +31,15 @@ export const updateAgSettings = async (username, projectName, data, font) => {
if (!setting.project[data.type.flavorType.flavor.name].font) {
setting.project[data.type.flavorType.flavor.name].font = font || '';
}
if (!setting.project[data.type.flavorType.flavor.name].fontSize) {
setting.project[data.type.flavorType.flavor.name].fontSize = fontSize || 1;
}
}
const savedFont = JSON.stringify(setting.project[data.type.flavorType.flavor.name].font);
const savedFontSize = JSON.stringify(setting.project[data.type.flavorType.flavor.name].fontSize);
setting.project[data.type.flavorType.flavor.name] = data.project[data.type.flavorType.flavor.name];
setting.project[data.type.flavorType.flavor.name].font = font || JSON.parse(savedFont);
setting.project[data.type.flavorType.flavor.name].fontSize = fontSize || JSON.parse(savedFontSize);
logger.debug('updateAgSettings.js', `Updating the ${environment.PROJECT_SETTING_FILE}`);
await fs.writeFileSync(folder, JSON.stringify(setting));
};
Expand All @@ -57,14 +62,19 @@ export const updateWebAgSettings = async (username, projectName, data) => {
} else {
setting.project[data.type.flavorType.flavor.name].font = (setting.project[data.type.flavorType.flavor.name].font) ? (setting.project[data.type.flavorType.flavor.name].font) : '';
}
if (!setting.project[data.type.flavorType.flavor.name].fontSize) {
setting.project[data.type.flavorType.flavor.name].fontSize = 1;
} else {
setting.project[data.type.flavorType.flavor.name].fontSize = (setting.project[data.type.flavorType.flavor.name].fontSize) ? (setting.project[data.type.flavorType.flavor.name].fontSize) : 1;
}
}
await sbStorageUpload(folder, JSON.stringify(setting), {
// cacheControl: '3600',
upsert: true,
});
};

export const saveReferenceResource = (font = '') => {
export const saveReferenceResource = (font = '', fontSize = 1) => {
logger.debug('updateAgSettings.js', 'In saveReferenceResource for saving the reference data');
localforage.getItem('currentProject').then(async (projectName) => {
const _projectname = await splitStringByLastOccurance(projectName, '_');
Expand All @@ -78,7 +88,7 @@ export const saveReferenceResource = (font = '') => {
if (id[0] === _projectname[1]) {
localforage.getItem('userProfile').then(async (value) => {
if (isElectron()) {
await updateAgSettings(value?.username, projectName, resources, font);
await updateAgSettings(value?.username, projectName, resources, font, fontSize);
} else {
await updateWebAgSettings(value?.user?.email, projectName, resources);
}
Expand Down
10 changes: 9 additions & 1 deletion renderer/src/layouts/editor/SectionPlaceholder1.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const SectionPlaceholder1 = ({ editor }) => {
font2,
fontSize1,
fontSize2,
editorFontSize,
selectedFont,
},
actions: {
setRow,
Expand Down Expand Up @@ -229,6 +231,8 @@ const SectionPlaceholder1 = ({ editor }) => {
setReferenceColumnOneData2,
setOpenResource1,
setOpenResource2,
selectedFont,
editorFontSize,
);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -238,7 +242,9 @@ const SectionPlaceholder1 = ({ editor }) => {
referenceColumnOneData2?.owner, removingSection, addingSection, referenceColumnOneData2?.offlineResource,
referenceColumnOneData1?.offlineResource, referenceColumnOneData2?.font,
referenceColumnOneData1?.font, resetResourceOnDeleteOffline?.referenceColumnOneData1Reset,
resetResourceOnDeleteOffline?.referenceColumnOneData2Reset, referenceColumnOneData2, referenceColumnOneData1]);
resetResourceOnDeleteOffline?.referenceColumnOneData2Reset, referenceColumnOneData2, referenceColumnOneData1,
referenceColumnOneData1?.fontSize, referenceColumnOneData2?.fontSize,
]);

// referenceColumnOneData2 referenceColumnOneData1
const CustomNavigation1 = (
Expand Down Expand Up @@ -299,6 +305,8 @@ const SectionPlaceholder1 = ({ editor }) => {
if (referenceColumnOneData2.font) {
setFont2(referenceColumnOneData2?.font);
}
setFontsize1(referenceColumnOneData1?.fontSize);
setFontsize2(referenceColumnOneData2?.fontSize);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [_obsNavigation1, _obsNavigation2, referenceColumnOneData1, referenceColumnOneData2]);

Expand Down
7 changes: 7 additions & 0 deletions renderer/src/layouts/editor/SectionPlaceholder2.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const SectionPlaceholder2 = ({ editor }) => {
font4,
fontSize3,
fontSize4,
selectedFont,
editorFontSize,
},
actions: {
setRow,
Expand Down Expand Up @@ -234,6 +236,8 @@ const SectionPlaceholder2 = ({ editor }) => {
setReferenceColumnTwoData2,
setOpenResource3,
setOpenResource4,
selectedFont,
editorFontSize,
);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -244,6 +248,7 @@ const SectionPlaceholder2 = ({ editor }) => {
referenceColumnTwoData1.offlineResource, referenceColumnTwoData2.offlineResource,
referenceColumnTwoData1.font, referenceColumnTwoData2.font,
resetResourceOnDeleteOffline?.referenceColumnTwoData1Reset, resetResourceOnDeleteOffline?.referenceColumnTwoData2Reset,
referenceColumnTwoData1.fontSize, referenceColumnTwoData2.fontSize,
]);

// referenceColumnTwoData1, referenceColumnTwoData2 openResource1, openResource2,
Expand Down Expand Up @@ -299,6 +304,8 @@ const SectionPlaceholder2 = ({ editor }) => {
if (referenceColumnTwoData2.font) {
setFont4(referenceColumnTwoData2?.font);
}
setFontsize3(referenceColumnTwoData1?.fontSize || 1);
setFontsize4(referenceColumnTwoData2?.fontSize || 1);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [_obsNavigation1, _obsNavigation2, referenceColumnTwoData1, referenceColumnTwoData2]);

Expand Down
6 changes: 3 additions & 3 deletions renderer/src/modules/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Editor({
setBookmarksVerses,
setObsNavigation,
handleSelectedFont,
setEditorFontSize,
handleEditorFontSize,
},
} = useContext(ReferenceContext);
const [bookMarked, setBookMarks] = useState(false);
Expand All @@ -55,10 +55,10 @@ export default function Editor({

const handleFontSize = (status) => {
if (status === 'dec' && editorFontSize > 0.70) {
setEditorFontSize(editorFontSize - 0.2);
handleEditorFontSize(editorFontSize - 0.2);
}
if (status === 'inc' && editorFontSize < 2) {
setEditorFontSize(editorFontSize + 0.2);
handleEditorFontSize(editorFontSize + 0.2);
}
};

Expand Down
1 change: 1 addition & 0 deletions renderer/src/util/createAudioVersification.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const createAudioVersification = (
refResources: call === 'edit' ? currentBurrito.project.audioTranslation.refResources : [],
bookMarks: call === 'edit' ? currentBurrito.project.audioTranslation.bookMarks : [],
font: '',
fontSize: 1,
},
},
sync: { services: { door43: [] } },
Expand Down
2 changes: 2 additions & 0 deletions renderer/src/util/createObsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const createObsContent = (
refResources: call === 'edit' ? currentBurrito.project.textStories.refResources : [],
bookMarks: call === 'edit' ? currentBurrito.project.textStories.bookMarks : [],
font: '',
fontSize: 1,
},
},
sync: { services: { door43: [] } },
Expand Down Expand Up @@ -372,6 +373,7 @@ export const createObsContent = (
},
sync: { services: { door43: [] } },
font: '',
fontSize: 1,
};
const stat = await uploadFileToSupabase(`${supabasePath}/${environment.PROJECT_SETTING_FILE}`, JSON.stringify(settings));
ingredients[path.join('ingredients', environment.PROJECT_SETTING_FILE)] = {
Expand Down
Loading

0 comments on commit 7628e08

Please sign in to comment.