Skip to content

Local/refactor #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 24, 2020
Merged

Local/refactor #181

merged 13 commits into from
Dec 24, 2020

Conversation

divyarajmasani
Copy link

@divyarajmasani divyarajmasani commented Dec 21, 2020

Summary

Updates Block API providers under block/api.
Though we now have separate Providers, the story data is being pulled by using the existing storyReducer from the dashboard, as many components, we are using for the story picker modal rely on it and we don't want to create redundant copies.

  • Uses npm package for the 'glider-js', and removed the added scripts from the repo.
  • Updated Story Picker modal to use Author Search similar to that of the story search. Also removed inefficient queries used for the authors.

NOTE: This PRs is for the ideation and if the API provider changes looks good, will incorporate the same in main PRs.

- Updates styled components for the story picker module for better alignment.
- Adds  class on Web Stories block wrapper if it's an AMP request.
- Removed 'glider-js' in favour of npm package for the same.
@divyarajmasani divyarajmasani self-assigned this Dec 21, 2020
@github-actions
Copy link

github-actions bot commented Dec 21, 2020

Size Change: -1.81 kB (0%)

Total Size: 2.02 MB

Filename Size Change
assets/js/carousel-script.js 0 B -730 B (removed) 🏆
assets/js/web-stories-block.js 535 kB -4.99 kB (-1%)
assets/js/web-stories-scripts.js 0 B -897 B (removed) 🏆
assets/css/carousel-view.css 718 B +718 B (new file) 🆕
assets/js/carousel-view.js 3.21 kB +3.21 kB (new file) 🆕
assets/js/lightbox.js 897 B +897 B (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 876 B 0 B
assets/css/stories-dashboard.css 929 B 0 B
assets/css/web-stories-block.css 1.38 kB -6 B (0%)
assets/css/web-stories-embed-block.css 580 B 0 B
assets/js/chunk-fonts-********************.js 44.3 kB 0 B
assets/js/chunk-web-stories-template-0-********************.js 10.7 kB 0 B
assets/js/chunk-web-stories-template-1-********************.js 11.2 kB 0 B
assets/js/chunk-web-stories-template-2-********************.js 11 kB 0 B
assets/js/chunk-web-stories-template-3-********************.js 11.2 kB 0 B
assets/js/chunk-web-stories-template-4-********************.js 12.6 kB 0 B
assets/js/chunk-web-stories-template-5-********************.js 7.07 kB 0 B
assets/js/chunk-web-stories-template-6-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-7-********************.js 10.3 kB 0 B
assets/js/chunk-web-stories-textset-0-********************.js 5.25 kB 0 B
assets/js/chunk-web-stories-textset-1-********************.js 6.54 kB 0 B
assets/js/chunk-web-stories-textset-2-********************.js 7.83 kB 0 B
assets/js/chunk-web-stories-textset-3-********************.js 15.2 kB 0 B
assets/js/chunk-web-stories-textset-4-********************.js 4.38 kB 0 B
assets/js/chunk-web-stories-textset-5-********************.js 5.68 kB 0 B
assets/js/chunk-web-stories-textset-6-********************.js 5.47 kB 0 B
assets/js/chunk-web-stories-textset-7-********************.js 10.3 kB 0 B
assets/js/edit-story.js 576 kB 0 B
assets/js/stories-dashboard.js 624 kB 0 B
assets/js/web-stories-activation-notice.js 74 kB 0 B
assets/js/web-stories-embed-block.js 17.4 kB 0 B

compressed-size-action

import { ERRORS } from '../../../dashboard/app/textContent';

const useStoryApi = (dataAdapter, { editStoryURL, storyApi }) => {
const [state, dispatch] = useReducer(storyReducer, defaultStoriesState);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy
As we discussed on PR #150 , in this PR I've taken some part from the web stories dashboard and created separate providers for the block.

Still for the stories data, I'm relying on the existing storyReducer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still for the stories data, I'm relying on the existing storyReducer.

Because it's so big & complex?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look big and complex at first but got hang of it 😅 . Now for the why we are still using it, we have added feature to rearrange selected stories, which relies on the data return from the existing storyReducer.

Now we can decouple it but at the moment it could take more time to go through the components used and identify how to remove the complete reliance.

This PR has removed reliance on dashboard API all but for the storyReducer. let me know your thoughts.

- Removes chunkSplitting for 'web-stories-scripts' due to issues with the bundle not loading, known issue with webpack v4.
* Stories 'order-by' values.
*/
export const ORDER_BY_OPTIONS = {
date: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe new-to-old for consistency? Although I do like the simplicity of date...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had kept it for simplicity but guess consistency is also important for the maintainability of the source. I'll update it.

Comment on lines 76 to 100
return (
<ConfigProvider config={config}>
{blockType === BLOCK_TYPE_LATEST_STORIES ? (
<LatestStoriesEdit
attributes={attributes}
setAttributes={setAttributes}
/>
) : blockType === BLOCK_TYPE_SELECTED_STORIES ? (
<SelectedStoriesEdit
icon={icon}
attributes={attributes}
setAttributes={setAttributes}
isSelected={isSelected}
/>
) : (
<StoryEmbedEdit
icon={icon}
attributes={attributes}
setAttributes={setAttributes}
className={className}
isSelected={isSelected}
/>
)}
</ConfigProvider>
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good opportunity to return early instead of using nested ternaries here, for readability.

if (blockType === BLOCK_TYPE_LATEST_STORIES) {
	return ();
}

if ( ...) {
	return ();
}

return ();

Comment on lines +378 to +382
/*
* amp-story-player's 'shadow-root-intermediary' element shows black space on top,
* because of the 'a' links. Making 'a' absolutely positioned removes them from normal
* relative flow, removes the space.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Maybe something to report upstream?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though this issue comes on non-AMP pages only due to the absence of css/ampshared.css.

Comment on lines 1 to 2
/* Import 'glider-js' styles. */
@import '../../node_modules/glider-js/glider.min.css';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: we really need some build tooling here for the CSS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried already but hit the roadblocks with some loader issues, I did set up basic sass build pipe but there were quite a few module build failures with imported components from the dashboard. Also there's an interesting issue with the webpack v4 and mini-css-extract-plugin when using multiple entries and chunks.

Issue: webpack-contrib/mini-css-extract-plugin#147

I resorted to removing the optimization for the webStoriesScript entry point, ( updating the PR ).

@@ -340,6 +341,7 @@ protected function get_block_classes() {

$block_classes = [];
$block_classes[] = 'web-stories-list';
$block_classes[] = ( $this->is_amp_request() ) ? 'is-amp' : '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding an is-amp class, the html element will have an amp attribute already, which you can target via CSS.

} from '../../../dashboard/app/reducer/stories';
import { ERRORS } from '../../../dashboard/app/textContent';

const useStoryApi = (dataAdapter, { editStoryURL, storyApi }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is editStoryURL needed here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editStoryURL is passed down to the storyReducer which returns the state with two data points

      bottomTargetAction: `${editStoryURL}&post=${id}`,
      editStoryLink: `${editStoryURL}&post=${id}`, 

Though these are not required for our case, but it was returning urls with undefined parts. hence added it.

- Update: Comments and Component refactoring for the blocks.
- Removes redundant component structures.
- Updates web stories block to use pre defined fields state for default state of the different views.
- Updates web stories block components to use field state, which is also an attribute for the block.
@divyarajmasani
Copy link
Author

Merging this to the base gutenberg blocks branch for inclusive review.

@divyarajmasani divyarajmasani marked this pull request as ready for review December 24, 2020 11:53
@divyarajmasani divyarajmasani merged commit 57f7889 into rt/gutenberg-blocks Dec 24, 2020
@divyarajmasani divyarajmasani deleted the local/refactor branch December 25, 2020 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants