Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Dec 5, 2023
1 parent 996b21e commit 42e8813
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
99 changes: 50 additions & 49 deletions app/assets/javascripts/qpixel_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ window.QPixel = {
* @param type the type to apply to the popup - warning, danger, etc.
* @param message the message to show
*/
createNotification: function(type, message) {
createNotification: function (type, message) {
// Some messages include a date stamp, `append_date` governs that.
let append_date = false;
let message_with_date = message;
Expand All @@ -66,26 +66,26 @@ window.QPixel = {
}
const span = '<span aria-hidden="true">&times;</span>';
const button = ('<button type="button" class="button is-close-button" data-dismiss="alert" aria-label="Close">' +
span + '</button>');
$("<div></div>")
.addClass("notice has-shadow-3 is-" + type)
.html(button + '<p>' + message_with_date + '</p>')
.css({
'position': 'fixed',
'top': '50px',
'left': '50%',
'transform': 'translateX(-50%)',
'width': '100%',
'max-width': '800px',
'cursor': 'pointer'
})
.on('click', function(ev) {
$(this).fadeOut(200, function() {
$(this).remove();
popped_modals_ct = popped_modals_ct > 0 ? (popped_modals_ct - 1) : 0;
});
})
.appendTo(document.body);
span + '</button>');
$('<div></div>')
.addClass('notice has-shadow-3 is-' + type)
.html(button + '<p>' + message_with_date + '</p>')
.css({
'position': 'fixed',
'top': '50px',
'left': '50%',
'transform': 'translateX(-50%)',
'width': '100%',
'max-width': '800px',
'cursor': 'pointer'
})
.on('click', function (ev) {
$(this).fadeOut(200, function () {
$(this).remove();
popped_modals_ct = popped_modals_ct > 0 ? (popped_modals_ct - 1) : 0;
});
})
.appendTo(document.body);
popped_modals_ct += 1;
},

Expand All @@ -94,7 +94,7 @@ window.QPixel = {
* @param el the element for which to find the offset.
* @returns {{top: integer, left: integer, bottom: integer, right: integer}}
*/
offset: function(el) {
offset: function (el) {
const topLeft = $(el).offset();
return {
top: topLeft.top,
Expand Down Expand Up @@ -190,21 +190,21 @@ window.QPixel = {
* FIFO-style fetch wrapper for /users/me requests
* @returns {Promise<Response>}
*/
_fetchUser() {
if(QPixel._pendingUserResponse) {
return QPixel._pendingUserResponse
_fetchUser () {
if (QPixel._pendingUserResponse) {
return QPixel._pendingUserResponse;
}

const myselfPromise = fetch('/users/me', {
credentials: 'include',
headers: {
'Accept': 'application/json'
}
credentials: 'include',
headers: {
'Accept': 'application/json'
}
});

QPixel._pendingUserResponse = myselfPromise;

return myselfPromise
return myselfPromise;
},

/**
Expand All @@ -217,14 +217,15 @@ window.QPixel = {
}

try {
const resp = await QPixel._fetchUser();
const resp = await QPixel._fetchUser();

if(!resp.bodyUsed) {
QPixel._user = await resp.json();
}
} finally {
// ensures pending user is cleared regardless of network errors
QPixel._pendingUserResponse = null;
if (!resp.bodyUsed) {
QPixel._user = await resp.json();
}
}
finally {
// ensures pending user is cleared regardless of network errors
QPixel._pendingUserResponse = null;
}

return QPixel._user;
Expand All @@ -245,8 +246,8 @@ window.QPixel = {
// Early return the preferences from localStorage unless null or undefined
const key = QPixel._preferencesLocalStorageKey();
const localStoragePreferences = (key in localStorage)
? JSON.parse(localStorage[key])
: null;
? JSON.parse(localStorage[key])
: null;
if (localStoragePreferences != null) {
QPixel._preferences = localStoragePreferences;
return QPixel._preferences;
Expand All @@ -266,15 +267,15 @@ window.QPixel = {
preference: async (name, community = false) => {
const user = await QPixel.user();

if(!user) {
return null
if (!user) {
return null;
}

let prefs = await QPixel._getPreferences();
let value = community ? prefs.community[name] : prefs.global[name];

// Note that null is a valid value for a preference, but undefined means we haven't fetched it.
if (typeof(value) !== 'undefined') {
if (typeof (value) !== 'undefined') {
return value;
}
// If we haven't fetched a preference, that probably means it's new - run a full re-fetch.
Expand All @@ -301,7 +302,7 @@ window.QPixel = {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, value, community })
body: JSON.stringify({name, value, community})
});
const data = await resp.json();
if (data.status !== 'success') {
Expand Down Expand Up @@ -342,8 +343,8 @@ window.QPixel = {
defaultFilter: async (categoryId) => {
const user = await QPixel.user();

if(!user) {
return '';
if (!user) {
return '';
}

const resp = await fetch(`/users/me/filters/default?category=${categoryId}`, {
Expand All @@ -366,7 +367,7 @@ window.QPixel = {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name })
body: JSON.stringify({name})
});
},

Expand All @@ -379,7 +380,7 @@ window.QPixel = {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(Object.assign(filter, { name, category, is_default: isDefault }))
body: JSON.stringify(Object.assign(filter, {name, category, is_default: isDefault}))
});
const data = await resp.json();
if (data.status !== 'success') {
Expand All @@ -401,7 +402,7 @@ window.QPixel = {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, system })
body: JSON.stringify({name, system})
});
const data = await resp.json();
if (data.status !== 'success') {
Expand Down Expand Up @@ -436,7 +437,7 @@ window.QPixel = {
// This prevents multiple calls from triggering multiple redundant '_fetchPreferences' calls
QPixel._cachedFetchPreferences = async () => {
await cachedPromise;
}
};
// Remember to await the promise so the very first call does not return before '_fetchPreferences' returns
await cachedPromise;
},
Expand Down
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@
t.boolean "is_top_level", default: false, null: false
t.boolean "is_freely_editable", default: false, null: false
t.string "icon_name"
t.bigint "answer_type_id"
t.boolean "has_reactions"
t.bigint "answer_type_id"
t.boolean "has_only_specific_reactions"
t.index ["answer_type_id"], name: "index_post_types_on_answer_type_id"
t.index ["name"], name: "index_post_types_on_name"
Expand Down Expand Up @@ -758,8 +758,8 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.boolean "read", default: false
t.index ["author_id"], name: "index_mod_messages_on_author_id"
t.index ["community_user_id"], name: "index_mod_messages_on_community_user_id"
t.index ["author_id"], name: "index_warnings_on_author_id"
t.index ["community_user_id"], name: "index_warnings_on_community_user_id"
end

add_foreign_key "abilities", "communities"
Expand Down

0 comments on commit 42e8813

Please sign in to comment.