Skip to content

Commit

Permalink
chore:resolved synk reported code quality cases (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
yssambare12 authored Oct 7, 2024
1 parent 7aa7884 commit 55e7544
Show file tree
Hide file tree
Showing 9 changed files with 2,985 additions and 2,470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,14 @@ const LocalFont = () => {
if ( response.success ) {
fontUpdated('Variation Added Successfully!');
}
setAddingFont( false );
} );
setAddingFont(false);
})
.catch((error) => {
console.error('Error during API request:', error);
fontUpdated('Failed to add variation. Please try again.');
setAddingFont(false);
});

};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,24 @@ const EditLocalFont = ({fontId}) => {
formData.append( 'font_id', fontId );
formData.append( 'font_data', JSON.stringify( editFontData ) );

apiFetch( {
apiFetch({
url: bsf_custom_fonts_admin.ajax_url,
method: 'POST',
body: formData,
} ).then( (response) => {
if ( response.success ) {
setTimeout( () => {
window.location = `${ bsf_custom_fonts_admin.app_base_url }`;
}, 500 );
})
.then((response) => {
if (response.success) {
setTimeout(() => {
window.location = `${bsf_custom_fonts_admin.app_base_url}`;
}, 500);
}
setLoading( false );
} );
setLoading(false);
})
.catch((error) => {
console.error('Error during API request:', error);
setLoading(false);
});

};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ const EditLocalPreviewItem = (fontId) => {
let defaultFont = `@font-face {\r\n\tfont-family: '${fontName}';`;
let srcFont = '';

variations.map((variation) => {
variations.forEach((variation) => {
let fontUrl = variation.font_url,
weight = variation.font_weight,
style = '' === variation.font_style ? 'normal' : variation.font_style,
src = '';

if ( Array.isArray( fontUrl ) ) {
fontUrl.map((url, index) => {
fontUrl.forEach((url, index) => {
src += ' url(\'' + url + '\') ';
src += getSrcFormat( url );
if ( index !== fontUrl.length - 1 ) {
Expand All @@ -59,7 +60,7 @@ const EditLocalPreviewItem = (fontId) => {
src += getSrcFormat( fontUrl );
}
srcFont += `${defaultFont}\r\n\tfont-style: ${style};\r\n\tfont-weight: ${weight};\r\n\tsrc: ${src};\r\n}\r\n`;
});
});

return srcFont;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const LocalPreviewItem = () => {
varsLength = variations.length,
counter = 0;

variations.map((variation) => {
if ( '' === variation.font_url ) {
counter = counter + 1;
}
});
variations.forEach((variation) => {
if ( '' === variation.font_url ) {
counter = counter + 1;
}
});

if ( varsLength === counter ) {
previewNameToggleCSS = `.preview-font-name {display: block;}`;
Expand Down Expand Up @@ -59,13 +59,13 @@ const LocalPreviewItem = () => {
let defaultFont = `@font-face {\r\n\tfont-family: '${fontName}';`;
let srcFont = '';

variations.map((variation) => {
variations.forEach((variation) => {
let fontUrl = variation.font_url,
weight = variation.font_weight,
style = '' === variation.font_style ? 'normal' : variation.font_style,
src = '';
src = '';
if ( Array.isArray( fontUrl ) ) {
fontUrl.map((url, index) => {
fontUrl.forEach((url, index) => {
src += ' url(\'' + url + '\') ';
src += getSrcFormat( url );
if ( index !== fontUrl.length - 1 ) {
Expand All @@ -78,7 +78,7 @@ const LocalPreviewItem = () => {
}
srcFont += `${defaultFont}\r\n\tfont-style: ${style};\r\n\tfont-weight: ${weight};\r\n\tsrc: ${src};\r\n}\r\n`;
});

return srcFont;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const ListItem = ({ item }) => {
window.location.reload();
}, 500 );
}
} );
} )
.catch((error) => {
console.error('Error during API request:', error);
});
};

const getFontWeightTitle = ( weight, type, style ) => {
Expand Down
18 changes: 13 additions & 5 deletions admin/dashboard/assets/src/dashboard-app/pages/welcome/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@ const Settings = () => {
formData.append( 'security', bsf_custom_fonts_admin.preload_font_nonce );
formData.append( 'isPreloading', ! isChecked );

apiFetch( {
apiFetch({
url: bsf_custom_fonts_admin.ajax_url,
method: 'POST',
body: formData,
} ).then( (response) => {
if ( response.success ) {
})
.then((response) => {
if (response.success) {
dispatch({
type: 'UPDATE_PRELOADING',
payload: ! isChecked,
payload: !isChecked,
});
}
} );
})
.catch((error) => {
console.error('Error during API request:', error);
dispatch({
type: 'API_REQUEST_FAILED',
payload: error.message || 'An error occurred. Please try again.',
});
});
};

const classNames = (...classes) => {
Expand Down
9 changes: 8 additions & 1 deletion admin/dashboard/assets/src/utils/setInitialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const setInitialState = ( store ) => {
};

store.dispatch( {type: 'UPDATE_INITIAL_STATE', payload: initialState} );
} );
} )
.catch((error) => {
console.error('Error fetching data:', error);
store.dispatch({
type: 'FETCH_SETTINGS_FAILED',
payload: error.message || 'Failed to fetch settings. Please try again.',
});
});
};

export default setInitialState;
54 changes: 36 additions & 18 deletions admin/dashboard/assets/src/utils/useApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ export const editFontToDB = (dispatch, fontId, googleFontData, cb) => {
url: bsf_custom_fonts_admin.ajax_url,
method: 'POST',
body: formData,
} ).then( (response) => {
if ( response.success ) {
//dispatch that banner
dispatch( { type: 'IS_DB_UPDATE_REQUIRED', payload: {isDbUpdateRequired: false, editType:''} } );
if(cb) cb(response.data.fontId);
})
.then((response) => {
if (response.success) {
// Dispatch that banner
dispatch({ type: 'IS_DB_UPDATE_REQUIRED', payload: { isDbUpdateRequired: false, editType: '' } });
if (cb) cb(response.data.fontId);
}
} );
})
.catch((error) => {
console.error('Error during API request:', error);
// You can also dispatch an error action here if needed
});
}

/**
Expand All @@ -41,16 +46,21 @@ export const deleteFontFromDB = (dispatch, fontId, cb) => {
formData.append( 'security', bsf_custom_fonts_admin.delete_font_nonce );
formData.append( 'font_id', fontId );

apiFetch( {
apiFetch({
url: bsf_custom_fonts_admin.ajax_url,
method: 'POST',
body: formData,
} ).then( (response) => {
if ( response.success ) {
dispatch( { type: 'IS_DB_UPDATE_REQUIRED', payload: {isDbUpdateRequired: false, editType:''} } );
if(cb) cb(response.data.fontId);
})
.then((response) => {
if (response.success) {
dispatch({ type: 'IS_DB_UPDATE_REQUIRED', payload: { isDbUpdateRequired: false, editType: '' } });
if (cb) cb(response.data.fontId);
}
} );
})
.catch((error) => {
console.error('Error during API request:', error);
});

}

/**
Expand All @@ -67,14 +77,22 @@ export const addFontToDB = ( dispatch, googleFontData, cb ) => {
formData.append( 'font_type', 'google' );
formData.append( 'font_data', JSON.stringify( googleFontData ) );

apiFetch( {
apiFetch({
url: bsf_custom_fonts_admin.ajax_url,
method: 'POST',
body: formData,
} ).then( (response) => {
if ( response.success ) {
dispatch( { type: 'IS_DB_UPDATE_REQUIRED', payload: {isDbUpdateRequired: false, editType:''} } );
if(cb) cb(response.data.fontId);
}).then((response) => {
if (response.success) {
dispatch({ type: 'IS_DB_UPDATE_REQUIRED', payload: { isDbUpdateRequired: false, editType: '' } });
if (cb) cb(response.data.fontId);
}
} );
})
.catch((error) => {
console.error('Error during API fetch:', error);
dispatch({
type: 'API_FETCH_ERROR',
payload: { message: 'Failed to update database. Please try again.', error: error.message },
});
});

};
Loading

0 comments on commit 55e7544

Please sign in to comment.