Skip to content

Commit

Permalink
bump frontend deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev committed Jan 18, 2022
1 parent 249dd5d commit 33cc6e6
Show file tree
Hide file tree
Showing 14 changed files with 1,430 additions and 3,849 deletions.
6 changes: 4 additions & 2 deletions frontend/app/__stubs__/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const validToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE1Nzk5ODY5ODIsImlzcyI6InJlbWFyazQyIiwibmJmIjoxNTc5OTg1MTIyLCJoYW5kc2hha2UiOnsiaWQiOiJkZXZfdXNlcjo6YXNkQHgxMDEucHcifX0.SLXLOE0Z8HQb2JwAvLS9fdrghwf8ndpuEjDsZvVE9O4' as const;
export const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE1Nzk5ODY5ODIsImlzcyI6InJlbWFyazQyIiwibmJmIjoxNTc5OTg1MTIyLCJoYW5kc2hha2UiOnsiaWQiOiJkZXZfdXNlcjo6YXNkQHgxM' as const;
export const validToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE1Nzk5ODY5ODIsImlzcyI6InJlbWFyazQyIiwibmJmIjoxNTc5OTg1MTIyLCJoYW5kc2hha2UiOnsiaWQiOiJkZXZfdXNlcjo6YXNkQHgxMDEucHcifX0.SLXLOE0Z8HQb2JwAvLS9fdrghwf8ndpuEjDsZvVE9O4' as const;
export const invalidToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE1Nzk5ODY5ODIsImlzcyI6InJlbWFyazQyIiwibmJmIjoxNTc5OTg1MTIyLCJoYW5kc2hha2UiOnsiaWQiOiJkZXZfdXNlcjo6YXNkQHgxM' as const;
2 changes: 1 addition & 1 deletion frontend/app/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const querySettings: Partial<QuerySettingsType> = parseQuery();

if (querySettings.max_shown_comments) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
querySettings.max_shown_comments = parseInt((querySettings.max_shown_comments as any) as string, 10);
querySettings.max_shown_comments = parseInt(querySettings.max_shown_comments as any as string, 10);
} else {
querySettings.max_shown_comments = MAX_SHOWN_ROOT_COMMENTS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { LS_EMAIL_KEY } from 'common/constants';

import { SubscribeByEmail, SubscribeByEmailForm } from '.';

const emailVerificationForSubscribeMock = (emailVerificationForSubscribe as unknown) as jest.Mock<
const emailVerificationForSubscribeMock = emailVerificationForSubscribe as unknown as jest.Mock<
ReturnType<typeof emailVerificationForSubscribe>
>;
const emailConfirmationForSubscribeMock = (emailConfirmationForSubscribe as unknown) as jest.Mock<
const emailConfirmationForSubscribeMock = emailConfirmationForSubscribe as unknown as jest.Mock<
ReturnType<typeof emailConfirmationForSubscribe>
>;
const unsubscribeFromEmailUpdatesMock = (unsubscribeFromEmailUpdates as unknown) as jest.Mock<
const unsubscribeFromEmailUpdatesMock = unsubscribeFromEmailUpdates as unknown as jest.Mock<
ReturnType<typeof unsubscribeFromEmailUpdates>
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
}

:global(.dark) .container {
background-color: rgba(var(--white-color), .12);
background-color: rgba(var(--white-color), 0.12);
}
141 changes: 76 additions & 65 deletions frontend/app/store/comments/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,98 @@ import { setItem } from 'common/local-storage';
import { LS_SORT_KEY } from 'common/constants';

/** sets comments, and put pinned comments in cache */
export const setComments = (comments: Node[]): StoreAction<void> => (dispatch) => {
dispatch({
type: COMMENTS_SET,
comments,
});
};
export const setComments =
(comments: Node[]): StoreAction<void> =>
(dispatch) => {
dispatch({
type: COMMENTS_SET,
comments,
});
};

/** appends comment to tree */
export const addComment = (text: string, title: string, pid?: Comment['id']): StoreAction<Promise<void>> => async (
dispatch
) => {
const comment = await api.addComment({ text, title, pid });
dispatch({ type: COMMENTS_APPEND, pid: pid || null, comment });
};
export const addComment =
(text: string, title: string, pid?: Comment['id']): StoreAction<Promise<void>> =>
async (dispatch) => {
const comment = await api.addComment({ text, title, pid });
dispatch({ type: COMMENTS_APPEND, pid: pid || null, comment });
};

/** edits comment in tree */
export const updateComment = (id: Comment['id'], text: string): StoreAction<Promise<void>> => async (dispatch) => {
const comment = await api.updateComment({ id, text });
dispatch({ type: COMMENTS_EDIT, comment });
};
export const updateComment =
(id: Comment['id'], text: string): StoreAction<Promise<void>> =>
async (dispatch) => {
const comment = await api.updateComment({ id, text });
dispatch({ type: COMMENTS_EDIT, comment });
};

/** edits comment in tree */
export const putVote = (id: Comment['id'], value: number): StoreAction<Promise<void>> => async (dispatch) => {
await api.putCommentVote({ id, value });
const comment = await api.getComment(id);
dispatch({ type: COMMENTS_EDIT, comment });
};
export const putVote =
(id: Comment['id'], value: number): StoreAction<Promise<void>> =>
async (dispatch) => {
await api.putCommentVote({ id, value });
const comment = await api.getComment(id);
dispatch({ type: COMMENTS_EDIT, comment });
};

/** edits comment in tree */
export const setPinState = (id: Comment['id'], value: boolean): StoreAction<Promise<void>> => async (
dispatch,
getState
) => {
if (value) {
await api.pinComment(id);
} else {
await api.unpinComment(id);
}
let comment = getState().comments.allComments[id];
comment = { ...comment, pin: value, edit: { summary: '', time: new Date().toISOString() } };
dispatch({ type: COMMENTS_EDIT, comment });
};
export const setPinState =
(id: Comment['id'], value: boolean): StoreAction<Promise<void>> =>
async (dispatch, getState) => {
if (value) {
await api.pinComment(id);
} else {
await api.unpinComment(id);
}
let comment = getState().comments.allComments[id];
comment = { ...comment, pin: value, edit: { summary: '', time: new Date().toISOString() } };
dispatch({ type: COMMENTS_EDIT, comment });
};

/** edits comment in tree */
export const removeComment = (id: Comment['id']): StoreAction<Promise<void>> => async (dispatch, getState) => {
const user = getState().user;
if (!user) return;
if (user.admin) {
await api.removeComment(id);
} else {
await api.removeMyComment(id);
}
let comment = getState().comments.allComments[id];
comment = { ...comment, delete: true, edit: { summary: '', time: new Date().toISOString() } };
dispatch({ type: COMMENTS_EDIT, comment });
};
export const removeComment =
(id: Comment['id']): StoreAction<Promise<void>> =>
async (dispatch, getState) => {
const user = getState().user;
if (!user) return;
if (user.admin) {
await api.removeComment(id);
} else {
await api.removeMyComment(id);
}
let comment = getState().comments.allComments[id];
comment = { ...comment, delete: true, edit: { summary: '', time: new Date().toISOString() } };
dispatch({ type: COMMENTS_EDIT, comment });
};

/** fetches comments from server */
export const fetchComments = (sort?: Sorting): StoreAction<Promise<Tree>> => async (dispatch, getState) => {
const { hiddenUsers, comments } = getState();
const hiddenUsersIds = Object.keys(hiddenUsers);
dispatch({ type: COMMENTS_REQUEST_FETCHING });
const data = await api.getPostComments(sort || comments.sort);
dispatch({ type: COMMENTS_REQUEST_SUCCESS });
if (hiddenUsersIds.length > 0) {
data.comments = filterTree(data.comments, (node) => hiddenUsersIds.indexOf(node.comment.user.id) === -1);
}
export const fetchComments =
(sort?: Sorting): StoreAction<Promise<Tree>> =>
async (dispatch, getState) => {
const { hiddenUsers, comments } = getState();
const hiddenUsersIds = Object.keys(hiddenUsers);
dispatch({ type: COMMENTS_REQUEST_FETCHING });
const data = await api.getPostComments(sort || comments.sort);
dispatch({ type: COMMENTS_REQUEST_SUCCESS });
if (hiddenUsersIds.length > 0) {
data.comments = filterTree(data.comments, (node) => hiddenUsersIds.indexOf(node.comment.user.id) === -1);
}

dispatch(setComments(data.comments));
dispatch(setPostInfo(data.info));
dispatch(setComments(data.comments));
dispatch(setPostInfo(data.info));

return data;
};
return data;
};

/** sets mode for comment, either reply or edit */
export const setCommentMode = (mode: StoreState['comments']['activeComment']): StoreAction<void> => (dispatch) => {
if (mode !== null && mode.state === CommentMode.None) {
mode = null;
}
dispatch(unsetCommentMode(mode));
};
export const setCommentMode =
(mode: StoreState['comments']['activeComment']): StoreAction<void> =>
(dispatch) => {
if (mode !== null && mode.state === CommentMode.None) {
mode = null;
}
dispatch(unsetCommentMode(mode));
};

/** unsets comment mode */
export function unsetCommentMode(mode: StoreState['comments']['activeComment'] = null) {
Expand Down
14 changes: 8 additions & 6 deletions frontend/app/store/comments/getters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Comment, CommentMode } from 'common/types';
import { StoreState } from '../index';

export const getCommentMode = (id: Comment['id']) => (state: StoreState): CommentMode => {
if (state.comments.activeComment === null || state.comments.activeComment.id !== id) {
return CommentMode.None;
}
export const getCommentMode =
(id: Comment['id']) =>
(state: StoreState): CommentMode => {
if (state.comments.activeComment === null || state.comments.activeComment.id !== id) {
return CommentMode.None;
}

return state.comments.activeComment.state;
};
return state.comments.activeComment.state;
};
12 changes: 7 additions & 5 deletions frontend/app/store/theme/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Theme } from 'common/types';
import { StoreAction } from '../';
import { THEME_SET } from './types';

export const setTheme = (theme: Theme): StoreAction<void> => (dispatch) =>
dispatch({
type: THEME_SET,
theme,
});
export const setTheme =
(theme: Theme): StoreAction<void> =>
(dispatch) =>
dispatch({
type: THEME_SET,
theme,
});
36 changes: 19 additions & 17 deletions frontend/app/store/thread/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ export const restoreCollapsedThreads = (): THREAD_RESTORE_COLLAPSE_ACTION => ({
ids: getCollapsedComments(),
});

export const setCollapse = (id: Comment['id'], value: boolean): StoreAction<void> => (dispatch, getState) => {
dispatch({
type: THREAD_SET_COLLAPSE,
id,
collapsed: value,
});
saveCollapsedComments(
siteId!,
url!,
Object.entries(getState().collapsedThreads).reduce((acc: string[], [key, value]) => {
if (value) {
acc.push(key);
}
return acc;
}, [])
);
};
export const setCollapse =
(id: Comment['id'], value: boolean): StoreAction<void> =>
(dispatch, getState) => {
dispatch({
type: THREAD_SET_COLLAPSE,
id,
collapsed: value,
});
saveCollapsedComments(
siteId!,
url!,
Object.entries(getState().collapsedThreads).reduce((acc: string[], [key, value]) => {
if (value) {
acc.push(key);
}
return acc;
}, [])
);
};
18 changes: 10 additions & 8 deletions frontend/app/store/thread/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { StaticStore } from 'common/static-store';

import { StoreState } from '../index';

export const getThreadIsCollapsed = (comment: Comment) => (state: StoreState): boolean => {
const collapsed = state.collapsedThreads[comment.id];
export const getThreadIsCollapsed =
(comment: Comment) =>
(state: StoreState): boolean => {
const collapsed = state.collapsedThreads[comment.id];

if (collapsed !== null && collapsed !== undefined) {
return collapsed;
}
if (collapsed !== null && collapsed !== undefined) {
return collapsed;
}

const score = comment.score || 0;
const score = comment.score || 0;

return score <= StaticStore.config.critical_score;
};
return score <= StaticStore.config.critical_score;
};
Loading

0 comments on commit 33cc6e6

Please sign in to comment.