Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Removing JQuery from save.js file #235

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/simulator/src/data/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,16 @@ async function generateImageForOnline() {
if (verilogModeGet()) {
var node = document.getElementsByClassName('CodeMirror')[0]
// var node = document.getElementsByClassName('CodeMirror')[0];
var prevHeight = $(node).css('height')
var prevWidth = $(node).css('width')
var prevHeight = window.getComputedStyle(node).height
var prevWidth = window.getComputedStyle(node).width
var baseWidth = 500
var baseHeight = Math.round(baseWidth / ratio)
$(node).css('height', baseHeight)
$(node).css('width', baseWidth)
node.style.height = baseHeight + 'px'
node.style.width = baseWidth + 'px'

var data = await domtoimage.toJpeg(node)
$(node).css('width', prevWidth)
$(node).css('height', prevHeight)
node.style.width = prevWidth
node.style.height = prevHeight
data = await crop(data, baseWidth, baseHeight)
return data
}
Expand Down Expand Up @@ -358,14 +358,16 @@ export default async function save() {

const data = await generateSaveData()
if (data instanceof Error) return
$('.loadingIcon').fadeIn()
let loadingIcon = document.querySelector('.loadingIcon');
loadingIcon.style.transition = 'opacity 0.5s linear';
loadingIcon.style.opacity = '1';

const projectName = getProjectName()
var imageData = await generateImageForOnline()

const headers = {
'Content-Type': 'application/json',
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
Authorization: `Token ${getToken('cvt')}`,
}

Expand All @@ -379,7 +381,11 @@ export default async function save() {
)
)
window.location.href = '/users/sign_in'
else $('.loadingIcon').fadeOut()
else {
let loadingIcon = document.querySelector('.loadingIcon')
loadingIcon.style.transition = 'opacity 0.2s';
loadingIcon.style.opacity = '0';
}
// eslint-disable-next-line camelcase
} else if ([0, undefined, null, '', '0'].includes(window.logixProjectId)) {
// Create new project - this part needs to be improved and optimised
Expand Down Expand Up @@ -432,7 +438,11 @@ export default async function save() {
showMessage(
`We have Created a new project: ${projectName} in our servers.`
)
$('.loadingIcon').fadeOut()

let loadingIcon = document.querySelector('.loadingIcon')
loadingIcon.style.transition = 'opacity 0.2s';
loadingIcon.style.opacity = '0';

localStorage.removeItem('recover')
const responseJson = response.json()
responseJson.then((data) => {
Expand Down Expand Up @@ -502,7 +512,9 @@ export default async function save() {
"There was an error, we couldn't save to our servers"
)
}
$('.loadingIcon').fadeOut()
let loadingIcon = document.querySelector('.loadingIcon')
loadingIcon.style.transition = 'opacity 0.2s';
loadingIcon.style.opacity = '0';
})
.catch((error) => {
console.error('Error:', error)
Expand Down
Loading