Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • to/cf-online-ui
  • vpfafrin/cf2021
2 results
Show changes
......@@ -16,8 +16,8 @@ const isLocalhost = Boolean(
window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
);
export function register(config) {
......@@ -43,7 +43,7 @@ export function register(config) {
navigator.serviceWorker.ready.then(() => {
console.log(
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://bit.ly/CRA-PWA"
"worker. To learn more, visit https://bit.ly/CRA-PWA",
);
});
} else {
......@@ -71,7 +71,7 @@ function registerValidSW(swUrl, config) {
// content until all client tabs are closed.
console.log(
"New content is available and will be used when all " +
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
"tabs for this page are closed. See https://bit.ly/CRA-PWA.",
);
// Execute callback
......@@ -123,7 +123,7 @@ function checkValidServiceWorker(swUrl, config) {
})
.catch(() => {
console.log(
"No internet connection found. App is running in offline mode."
"No internet connection found. App is running in offline mode.",
);
});
}
......
......@@ -63,7 +63,7 @@ export const getGroupByCode = memoize(
(groupMappings, groupCode) => {
return groupMappings.find((gm) => gm.code === groupCode);
},
(groupMappings, groupCode) => [groupMappings, groupCode]
(groupMappings, groupCode) => [groupMappings, groupCode],
);
export const getGroupsByCode = memoize((groupMappings, groupCodes) => {
......
......@@ -7,7 +7,8 @@ import WaitQueue from "wait-queue";
import { markdownConverter } from "markdown";
export const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
export const urlRegex =
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
export const seenPostsLSKey = "cf2021_seen_posts";
export const seenAnnouncementsLSKey = "cf2021_seen_announcements";
......@@ -38,7 +39,7 @@ export const filterPosts = (filters, allItems) => {
if (!filters.showPendingProposals) {
filteredItems = filteredItems.filter(
(item) => item.type === "post" || item.state !== "pending"
(item) => item.type === "post" || item.state !== "pending",
);
}
......@@ -55,7 +56,7 @@ export const filterPosts = (filters, allItems) => {
*/
export const updateWindowPosts = (state) => {
state.window.items = filterPosts(state.filters, values(state.items)).map(
property("id")
property("id"),
);
};
......@@ -168,7 +169,7 @@ export const parseRawAnnouncement = (rawAnnouncement) => {
datetime: parse(
rawAnnouncement.datetime,
"yyyy-MM-dd HH:mm:ss",
new Date()
new Date(),
),
type: announcementTypeMapping[rawAnnouncement.type],
seen: isSeen(seenAnnouncementsLSKey, rawAnnouncement.id),
......@@ -183,7 +184,7 @@ export const createSeenWriter = (localStorageKey) => {
const seenWriterWorker = async () => {
const id = await queue.shift();
const seen = new Set(
(localStorage.getItem(localStorageKey) || "").split(",")
(localStorage.getItem(localStorageKey) || "").split(","),
);
seen.add(id);
......
......@@ -103,7 +103,7 @@ export const connect = ({ url, onConnect }) => {
});
console.log(
"[ws] Socket is closed. Reconnect will be attempted in 1 second.",
event.reason
event.reason,
);
clearInterval(keepAliveInterval);
......@@ -114,7 +114,7 @@ export const connect = ({ url, onConnect }) => {
console.error(
"[ws] Socket encountered error: ",
err.message,
"Closing socket"
"Closing socket",
);
ws.close();
reject(err);
......
......@@ -10,7 +10,7 @@ export const handleAnnouncementChanged = (payload) => {
if (has(payload, "content")) {
state.items[payload.id].content = payload.content;
state.items[payload.id].contentHtml = markdownConverter.makeHtml(
payload.content
payload.content,
);
}
if (has(payload, "link")) {
......
import has from "lodash/has";
import throttle from "lodash/throttle";
import { markdownConverter } from "markdown";
import { PostStore } from "stores";
import { parseRawPost, postsStateMapping, updateWindowPosts } from "utils";
/**
* Re-apply sorting by rank but no more than once every 3 seconds.
*/
const sortOnRankThrottled = throttle(() => {
PostStore.update((state) => {
if (state.filters.sort === "byScore") {
updateWindowPosts(state);
}
});
}, 5000);
export const handlePostRanked = (payload) => {
PostStore.update((state) => {
if (state.items[payload.id]) {
......@@ -12,12 +24,11 @@ export const handlePostRanked = (payload) => {
state.items[payload.id].ranking.score =
state.items[payload.id].ranking.likes -
state.items[payload.id].ranking.dislikes;
if (state.filters.sort === "byScore") {
updateWindowPosts(state);
}
}
});
// Run sorting in a throttled manner.
sortOnRankThrottled();
};
export const handlePostChanged = (payload) => {
......@@ -26,20 +37,20 @@ export const handlePostChanged = (payload) => {
if (has(payload, "content")) {
state.items[payload.id].content = payload.content;
state.items[payload.id].contentHtml = markdownConverter.makeHtml(
payload.content
payload.content,
);
state.items[payload.id].modified = true;
}
if (has(payload, "state")) {
state.items[payload.id].state = postsStateMapping[payload.state];
updateWindowPosts(state);
}
if (has(payload, "is_archived")) {
state.items[payload.id].archived = payload.is_archived;
updateWindowPosts(state);
}
updateWindowPosts(state);
}
});
};
......
import has from "lodash/has";
import { loadPosts } from "actions/posts";
import { markdownConverter } from "markdown";
import { ProgramStore } from "stores";
......@@ -19,9 +20,18 @@ export const handleProgramEntryChanged = (payload) => {
if (has(payload, "description")) {
state.items[payload.id].description = payload.description;
state.items[payload.id].htmlContent = markdownConverter.makeHtml(
payload.description
payload.description,
);
}
if (has(payload, "is_live") && payload.is_live) {
state.currentId = payload.id;
}
}
});
if (has(payload, "is_live") && payload.is_live) {
// Re-load posts - these are bound directly to the program schedule entry.
loadPosts.run({}, { respectCache: false });
}
};