@gravity-ui/blog-constructor 2.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.0](https://github.com/gravity-ui/blog-constructor/compare/v2.3.0...v3.0.0) (2023-04-10)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * add callback prop for blog page ([#25](https://github.com/gravity-ui/blog-constructor/issues/25))
9
+
10
+ ### Features
11
+
12
+ * add callback prop for blog page ([#25](https://github.com/gravity-ui/blog-constructor/issues/25)) ([7b1ab2c](https://github.com/gravity-ui/blog-constructor/commit/7b1ab2c12aa9ef4f8e5a11853508a9b439a196d7))
13
+
3
14
  ## [2.3.0](https://github.com/gravity-ui/blog-constructor/compare/v2.2.0...v2.3.0) (2023-04-10)
4
15
 
5
16
 
@@ -38,7 +38,6 @@ const Posts_1 = require("../../components/Posts/Posts");
38
38
  const PostsError_1 = require("../../components/PostsError/PostsError");
39
39
  const constants_1 = require("../../constants");
40
40
  const FeedContext_1 = require("../../contexts/FeedContext");
41
- const LocaleContext_1 = require("../../contexts/LocaleContext");
42
41
  const RouterContext_1 = require("../../contexts/RouterContext");
43
42
  /**
44
43
  * @deprecated Metrika will be deleted after launch of analyticsEvents
@@ -56,7 +55,6 @@ const Feed = ({ image }) => {
56
55
  var _a;
57
56
  const { posts, totalCount, tags, services, pinnedPost, getPosts, pageCountForShowSupportButtons, } = (0, react_1.useContext)(FeedContext_1.FeedContext);
58
57
  const router = (0, react_1.useContext)(RouterContext_1.RouterContext);
59
- const { locale } = (0, react_1.useContext)(LocaleContext_1.LocaleContext);
60
58
  const handleAnalytics = (0, page_constructor_1.useAnalytics)(common_1.DefaultEventNames.ShowMore);
61
59
  const [{ errorLoad, errorShowMore, isFetching, isShowMoreFetching, isShowMoreVisible, lastLoadedCount, postCountOnPage, postsOnPage, pinnedPostOnPage, currentPage, queryParams, }, dispatch,] = (0, react_1.useReducer)(reducer_1.reducer, {
62
60
  errorLoad: false,
@@ -79,6 +77,12 @@ const Feed = ({ image }) => {
79
77
  };
80
78
  const handleChangeQueryParams = (value) => {
81
79
  dispatch({ type: reducer_1.ActionTypes.QueryParamsChange, payload: value });
80
+ const hasFirstPageQuery = Object.keys(value).some((queryKey) => queryKey === PAGE_QUERY && value[queryKey] === FIRST_PAGE);
81
+ if (hasFirstPageQuery) {
82
+ // eslint-disable-next-line no-not-accumulator-reassign/no-not-accumulator-reassign
83
+ value[PAGE_QUERY] = null;
84
+ }
85
+ router.updateQueryCallback(value);
82
86
  };
83
87
  const handlePageChange = async (value) => {
84
88
  pageChange(value);
@@ -169,22 +173,6 @@ const Feed = ({ image }) => {
169
173
  value: tag.slug,
170
174
  icon: tag.icon && react_1.default.createElement(uikit_1.Icon, { data: tag.icon }),
171
175
  })), [tags]);
172
- (0, react_1.useEffect)(() => {
173
- const queryString = Object.keys(queryParams)
174
- .reduce((acc, curr) => {
175
- if (curr === PAGE_QUERY && queryParams[curr] === FIRST_PAGE) {
176
- return acc;
177
- }
178
- if (queryParams[curr]) {
179
- acc.push(`${curr}=${queryParams[curr]}`);
180
- }
181
- return acc;
182
- }, [])
183
- .join('&');
184
- const pathPrefix = (locale === null || locale === void 0 ? void 0 : locale.pathPrefix) ? `/${locale === null || locale === void 0 ? void 0 : locale.pathPrefix}/` : '/';
185
- const newUrl = `${pathPrefix}blog${queryString ? `?${queryString}` : ''}`;
186
- window.history.replaceState(Object.assign(Object.assign({}, window.history.state), { as: newUrl, url: newUrl }), '', newUrl);
187
- }, [locale === null || locale === void 0 ? void 0 : locale.pathPrefix, queryParams]);
188
176
  return (react_1.default.createElement("div", null,
189
177
  react_1.default.createElement(FeedHeader_1.FeedHeader, { verticalOffset: "s", tags: tagItems, services: serviceItems, setIsFetching: setIsFetching, handleChangeQuery: handleChangeQueryParams, queryParams: queryParams, background: {
190
178
  fullWidth: true,
@@ -5,5 +5,6 @@ export interface RouterContextProps {
5
5
  as: string;
6
6
  hostname: string;
7
7
  query?: Query;
8
+ updateQueryCallback: (query: Query) => void;
8
9
  }
9
10
  export declare const RouterContext: React.Context<RouterContextProps>;
@@ -9,7 +9,6 @@ import { Posts } from '../../components/Posts/Posts';
9
9
  import { PostsError } from '../../components/PostsError/PostsError';
10
10
  import { BlogMetrikaGoalIds } from '../../constants';
11
11
  import { FeedContext } from '../../contexts/FeedContext';
12
- import { LocaleContext } from '../../contexts/LocaleContext';
13
12
  import { RouterContext } from '../../contexts/RouterContext';
14
13
  /**
15
14
  * @deprecated Metrika will be deleted after launch of analyticsEvents
@@ -27,7 +26,6 @@ export const Feed = ({ image }) => {
27
26
  var _a;
28
27
  const { posts, totalCount, tags, services, pinnedPost, getPosts, pageCountForShowSupportButtons, } = useContext(FeedContext);
29
28
  const router = useContext(RouterContext);
30
- const { locale } = useContext(LocaleContext);
31
29
  const handleAnalytics = useAnalytics(DefaultEventNames.ShowMore);
32
30
  const [{ errorLoad, errorShowMore, isFetching, isShowMoreFetching, isShowMoreVisible, lastLoadedCount, postCountOnPage, postsOnPage, pinnedPostOnPage, currentPage, queryParams, }, dispatch,] = useReducer(reducer, {
33
31
  errorLoad: false,
@@ -50,6 +48,12 @@ export const Feed = ({ image }) => {
50
48
  };
51
49
  const handleChangeQueryParams = (value) => {
52
50
  dispatch({ type: ActionTypes.QueryParamsChange, payload: value });
51
+ const hasFirstPageQuery = Object.keys(value).some((queryKey) => queryKey === PAGE_QUERY && value[queryKey] === FIRST_PAGE);
52
+ if (hasFirstPageQuery) {
53
+ // eslint-disable-next-line no-not-accumulator-reassign/no-not-accumulator-reassign
54
+ value[PAGE_QUERY] = null;
55
+ }
56
+ router.updateQueryCallback(value);
53
57
  };
54
58
  const handlePageChange = async (value) => {
55
59
  pageChange(value);
@@ -140,22 +144,6 @@ export const Feed = ({ image }) => {
140
144
  value: tag.slug,
141
145
  icon: tag.icon && React.createElement(Icon, { data: tag.icon }),
142
146
  })), [tags]);
143
- useEffect(() => {
144
- const queryString = Object.keys(queryParams)
145
- .reduce((acc, curr) => {
146
- if (curr === PAGE_QUERY && queryParams[curr] === FIRST_PAGE) {
147
- return acc;
148
- }
149
- if (queryParams[curr]) {
150
- acc.push(`${curr}=${queryParams[curr]}`);
151
- }
152
- return acc;
153
- }, [])
154
- .join('&');
155
- const pathPrefix = (locale === null || locale === void 0 ? void 0 : locale.pathPrefix) ? `/${locale === null || locale === void 0 ? void 0 : locale.pathPrefix}/` : '/';
156
- const newUrl = `${pathPrefix}blog${queryString ? `?${queryString}` : ''}`;
157
- window.history.replaceState(Object.assign(Object.assign({}, window.history.state), { as: newUrl, url: newUrl }), '', newUrl);
158
- }, [locale === null || locale === void 0 ? void 0 : locale.pathPrefix, queryParams]);
159
147
  return (React.createElement("div", null,
160
148
  React.createElement(FeedHeader, { verticalOffset: "s", tags: tagItems, services: serviceItems, setIsFetching: setIsFetching, handleChangeQuery: handleChangeQueryParams, queryParams: queryParams, background: {
161
149
  fullWidth: true,
@@ -5,5 +5,6 @@ export interface RouterContextProps {
5
5
  as: string;
6
6
  hostname: string;
7
7
  query?: Query;
8
+ updateQueryCallback: (query: Query) => void;
8
9
  }
9
10
  export declare const RouterContext: React.Context<RouterContextProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/blog-constructor",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
4
4
  "description": "Gravity UI Blog Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {