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( ...@@ -16,8 +16,8 @@ const isLocalhost = Boolean(
window.location.hostname === "[::1]" || window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4. // 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match( 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) { export function register(config) {
...@@ -43,7 +43,7 @@ export function register(config) { ...@@ -43,7 +43,7 @@ export function register(config) {
navigator.serviceWorker.ready.then(() => { navigator.serviceWorker.ready.then(() => {
console.log( console.log(
"This web app is being served cache-first by a service " + "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 { } else {
...@@ -71,7 +71,7 @@ function registerValidSW(swUrl, config) { ...@@ -71,7 +71,7 @@ function registerValidSW(swUrl, config) {
// content until all client tabs are closed. // content until all client tabs are closed.
console.log( console.log(
"New content is available and will be used when all " + "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 // Execute callback
...@@ -123,7 +123,7 @@ function checkValidServiceWorker(swUrl, config) { ...@@ -123,7 +123,7 @@ function checkValidServiceWorker(swUrl, config) {
}) })
.catch(() => { .catch(() => {
console.log( 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( ...@@ -63,7 +63,7 @@ export const getGroupByCode = memoize(
(groupMappings, groupCode) => { (groupMappings, groupCode) => {
return groupMappings.find((gm) => gm.code === groupCode); return groupMappings.find((gm) => gm.code === groupCode);
}, },
(groupMappings, groupCode) => [groupMappings, groupCode] (groupMappings, groupCode) => [groupMappings, groupCode],
); );
export const getGroupsByCode = memoize((groupMappings, groupCodes) => { export const getGroupsByCode = memoize((groupMappings, groupCodes) => {
......
...@@ -7,7 +7,8 @@ import WaitQueue from "wait-queue"; ...@@ -7,7 +7,8 @@ import WaitQueue from "wait-queue";
import { markdownConverter } from "markdown"; 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 seenPostsLSKey = "cf2021_seen_posts";
export const seenAnnouncementsLSKey = "cf2021_seen_announcements"; export const seenAnnouncementsLSKey = "cf2021_seen_announcements";
...@@ -38,7 +39,7 @@ export const filterPosts = (filters, allItems) => { ...@@ -38,7 +39,7 @@ export const filterPosts = (filters, allItems) => {
if (!filters.showPendingProposals) { if (!filters.showPendingProposals) {
filteredItems = filteredItems.filter( 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) => { ...@@ -55,7 +56,7 @@ export const filterPosts = (filters, allItems) => {
*/ */
export const updateWindowPosts = (state) => { export const updateWindowPosts = (state) => {
state.window.items = filterPosts(state.filters, values(state.items)).map( state.window.items = filterPosts(state.filters, values(state.items)).map(
property("id") property("id"),
); );
}; };
...@@ -168,7 +169,7 @@ export const parseRawAnnouncement = (rawAnnouncement) => { ...@@ -168,7 +169,7 @@ export const parseRawAnnouncement = (rawAnnouncement) => {
datetime: parse( datetime: parse(
rawAnnouncement.datetime, rawAnnouncement.datetime,
"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss",
new Date() new Date(),
), ),
type: announcementTypeMapping[rawAnnouncement.type], type: announcementTypeMapping[rawAnnouncement.type],
seen: isSeen(seenAnnouncementsLSKey, rawAnnouncement.id), seen: isSeen(seenAnnouncementsLSKey, rawAnnouncement.id),
...@@ -183,7 +184,7 @@ export const createSeenWriter = (localStorageKey) => { ...@@ -183,7 +184,7 @@ export const createSeenWriter = (localStorageKey) => {
const seenWriterWorker = async () => { const seenWriterWorker = async () => {
const id = await queue.shift(); const id = await queue.shift();
const seen = new Set( const seen = new Set(
(localStorage.getItem(localStorageKey) || "").split(",") (localStorage.getItem(localStorageKey) || "").split(","),
); );
seen.add(id); seen.add(id);
......
...@@ -103,7 +103,7 @@ export const connect = ({ url, onConnect }) => { ...@@ -103,7 +103,7 @@ export const connect = ({ url, onConnect }) => {
}); });
console.log( console.log(
"[ws] Socket is closed. Reconnect will be attempted in 1 second.", "[ws] Socket is closed. Reconnect will be attempted in 1 second.",
event.reason event.reason,
); );
clearInterval(keepAliveInterval); clearInterval(keepAliveInterval);
...@@ -114,7 +114,7 @@ export const connect = ({ url, onConnect }) => { ...@@ -114,7 +114,7 @@ export const connect = ({ url, onConnect }) => {
console.error( console.error(
"[ws] Socket encountered error: ", "[ws] Socket encountered error: ",
err.message, err.message,
"Closing socket" "Closing socket",
); );
ws.close(); ws.close();
reject(err); reject(err);
......
...@@ -10,7 +10,7 @@ export const handleAnnouncementChanged = (payload) => { ...@@ -10,7 +10,7 @@ export const handleAnnouncementChanged = (payload) => {
if (has(payload, "content")) { if (has(payload, "content")) {
state.items[payload.id].content = payload.content; state.items[payload.id].content = payload.content;
state.items[payload.id].contentHtml = markdownConverter.makeHtml( state.items[payload.id].contentHtml = markdownConverter.makeHtml(
payload.content payload.content,
); );
} }
if (has(payload, "link")) { if (has(payload, "link")) {
......
import has from "lodash/has"; import has from "lodash/has";
import throttle from "lodash/throttle";
import { markdownConverter } from "markdown"; import { markdownConverter } from "markdown";
import { PostStore } from "stores"; import { PostStore } from "stores";
import { parseRawPost, postsStateMapping, updateWindowPosts } from "utils"; 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) => { export const handlePostRanked = (payload) => {
PostStore.update((state) => { PostStore.update((state) => {
if (state.items[payload.id]) { if (state.items[payload.id]) {
...@@ -12,12 +24,11 @@ export const handlePostRanked = (payload) => { ...@@ -12,12 +24,11 @@ export const handlePostRanked = (payload) => {
state.items[payload.id].ranking.score = state.items[payload.id].ranking.score =
state.items[payload.id].ranking.likes - state.items[payload.id].ranking.likes -
state.items[payload.id].ranking.dislikes; state.items[payload.id].ranking.dislikes;
if (state.filters.sort === "byScore") {
updateWindowPosts(state);
}
} }
}); });
// Run sorting in a throttled manner.
sortOnRankThrottled();
}; };
export const handlePostChanged = (payload) => { export const handlePostChanged = (payload) => {
...@@ -26,20 +37,20 @@ export const handlePostChanged = (payload) => { ...@@ -26,20 +37,20 @@ export const handlePostChanged = (payload) => {
if (has(payload, "content")) { if (has(payload, "content")) {
state.items[payload.id].content = payload.content; state.items[payload.id].content = payload.content;
state.items[payload.id].contentHtml = markdownConverter.makeHtml( state.items[payload.id].contentHtml = markdownConverter.makeHtml(
payload.content payload.content,
); );
state.items[payload.id].modified = true; state.items[payload.id].modified = true;
} }
if (has(payload, "state")) { if (has(payload, "state")) {
state.items[payload.id].state = postsStateMapping[payload.state]; state.items[payload.id].state = postsStateMapping[payload.state];
updateWindowPosts(state);
} }
if (has(payload, "is_archived")) { if (has(payload, "is_archived")) {
state.items[payload.id].archived = payload.is_archived; state.items[payload.id].archived = payload.is_archived;
updateWindowPosts(state);
} }
updateWindowPosts(state);
} }
}); });
}; };
......
import has from "lodash/has"; import has from "lodash/has";
import { loadPosts } from "actions/posts";
import { markdownConverter } from "markdown"; import { markdownConverter } from "markdown";
import { ProgramStore } from "stores"; import { ProgramStore } from "stores";
...@@ -19,9 +20,18 @@ export const handleProgramEntryChanged = (payload) => { ...@@ -19,9 +20,18 @@ export const handleProgramEntryChanged = (payload) => {
if (has(payload, "description")) { if (has(payload, "description")) {
state.items[payload.id].description = payload.description; state.items[payload.id].description = payload.description;
state.items[payload.id].htmlContent = markdownConverter.makeHtml( 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 });
}
}; };