diff --git a/CHANGELOG.md b/CHANGELOG.md index 1202b115..06d2cffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Change BigQuery source type name from 'bq' to 'bigquery' [#203](https://github.com/CartoDB/carto-react-template/pull/203) - Add new hygen generators for components, models and slices [#171](https://github.com/CartoDB/carto-react-template/pull/171) - Adapt to new **multi-package** structure for carto-react libs [#206](https://github.com/CartoDB/carto-react-lib/pull/206) +- Fix layer generator with second layer [#204](https://github.com/CartoDB/carto-react-template/pull/204) ## 1.0.0-beta12 (2021-02-08) - Refactor on basic JSX & JS stuff [#170](https://github.com/CartoDB/carto-react-template/pull/170) diff --git a/hygen/_templates/layer/new/inject_view_useEffect.ejs.t b/hygen/_templates/layer/new/inject_view_first_useEffect.ejs.t similarity index 100% rename from hygen/_templates/layer/new/inject_view_useEffect.ejs.t rename to hygen/_templates/layer/new/inject_view_first_useEffect.ejs.t diff --git a/hygen/_templates/layer/new/inject_view_import_actionsSlice.ejs.t b/hygen/_templates/layer/new/inject_view_import_actionsSlice.ejs.t index 7b97d2e8..1893f1aa 100644 --- a/hygen/_templates/layer/new/inject_view_import_actionsSlice.ejs.t +++ b/hygen/_templates/layer/new/inject_view_import_actionsSlice.ejs.t @@ -1,7 +1,8 @@ --- inject: true to: "<%= attach ? `src/${view_path}` : null %>" -after: "'react'" -skip_if: "addLayer" +after: "from 'react'" +skip_if: \{ addLayer, --- + import { addLayer, removeLayer, addSource, removeSource } from '@carto/react-redux'; diff --git a/hygen/_templates/layer/new/inject_view_import_layer_id.ejs.t b/hygen/_templates/layer/new/inject_view_import_layer_id.ejs.t index ab090178..3c48ad99 100644 --- a/hygen/_templates/layer/new/inject_view_import_layer_id.ejs.t +++ b/hygen/_templates/layer/new/inject_view_import_layer_id.ejs.t @@ -4,4 +4,4 @@ to: "<%= attach ? `src/${view_path}` : null %>" after: "from 'react'" skip_if: "import { <%= h.changeCase.constantCase(name) %>_ID" --- -import { <%= h.changeCase.constantCase(name) %>_ID } from 'components/layers/<%= h.changeCase.pascalCase(name) -%>'; +import { <%= h.changeCase.constantCase(name) %>_ID } from 'components/layers/<%= h.changeCase.pascalCase(name) -%>'; \ No newline at end of file diff --git a/hygen/_templates/layer/new/inject_view_import_source.ejs.t b/hygen/_templates/layer/new/inject_view_import_source.ejs.t index dea224ee..ea465878 100644 --- a/hygen/_templates/layer/new/inject_view_import_source.ejs.t +++ b/hygen/_templates/layer/new/inject_view_import_source.ejs.t @@ -4,4 +4,4 @@ to: "<%= attach ? `src/${view_path}` : null %>" after: "from 'react'" skip_if: "<%= `data/sources/${source_file}` %>" --- -import <%= h.changeCase.camelCase(source_file) %> from 'data/sources/<%= h.changeCase.camelCase(source_file) %>'; +import <%= h.changeCase.camelCase(source_file) %> from 'data/sources/<%= h.changeCase.camelCase(source_file) %>'; \ No newline at end of file diff --git a/hygen/_templates/layer/new/inject_view_splitted_useEffect_addLayer.ejs.t b/hygen/_templates/layer/new/inject_view_splitted_useEffect_addLayer.ejs.t new file mode 100644 index 00000000..0b0de20f --- /dev/null +++ b/hygen/_templates/layer/new/inject_view_splitted_useEffect_addLayer.ejs.t @@ -0,0 +1,13 @@ +--- +inject: true +to: "<%= attach ? `src/${view_path}` : null %>" +after: addSource\(<%= h.changeCase.camelCase(source_file) %>\)\n[ \t]*\)|addSource\(<%= h.changeCase.camelCase(source_file) %>\)\); +skip_if: <%= h.changeCase.constantCase(name) %>_ID, +--- + + dispatch( + addLayer({ + id: <%= h.changeCase.constantCase(name) %>_ID, + source: <%= h.changeCase.camelCase(source_file) %>.id, + }) + ); \ No newline at end of file diff --git a/hygen/_templates/layer/new/inject_view_splitted_useEffect_remove.ejs.t b/hygen/_templates/layer/new/inject_view_splitted_useEffect_remove.ejs.t new file mode 100644 index 00000000..85f8147a --- /dev/null +++ b/hygen/_templates/layer/new/inject_view_splitted_useEffect_remove.ejs.t @@ -0,0 +1,8 @@ +--- +inject: true +to: "<%= attach ? `src/${view_path}` : null %>" +before: dispatch\(removeSource\(<%= h.changeCase.camelCase(source_file) %>.id\)\); +skip_if: dispatch\(removeLayer\(<%= h.changeCase.constantCase(name) %>_ID\)\); +--- + + dispatch(removeLayer(<%= h.changeCase.constantCase(name) %>_ID)); \ No newline at end of file