Skip to content

Commit

Permalink
fix: initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhou-bit committed Nov 13, 2023
1 parent 65eee08 commit 2674607
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ LibrarySelector.defaultProps = {
LibrarySelector.propTypes = {
studioEndpointUrl: PropTypes.string.isRequired,
// redux
libraries: PropTypes.shape([]),
libraries: PropTypes.array,
loadLibrary: PropTypes.func.isRequired,
selectedLibrary: PropTypes.number,
onSelectLibrary: PropTypes.func.isRequired,
settings: PropTypes.shape({}),
settings: PropTypes.object,
unloadLibrary: PropTypes.func.isRequired,
};

Expand Down
2 changes: 1 addition & 1 deletion src/editors/containers/LibraryContentEditor/data/urls.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const contentStore = ({ studioEndpointUrl }) => (
`${studioEndpointUrl}/api/libraries/v1/home/`
`${studioEndpointUrl}/api/contentstore/v1/home/`
);

export const libraryProperty = ({ studioEndpointUrl, libraryId }) => (
Expand Down
75 changes: 36 additions & 39 deletions src/editors/containers/LibraryContentEditor/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,52 @@ import { modes } from './constants';
import api from './data/api';

export const useLibraryHook = ({
blockFailed,
blockFinished,
blockValue,
initialize,
libraryPayload,
studioEndpointUrl,
}) => {
useEffect(() => {
if (blockFinished && !blockFailed) {
const libraries = api.fetchContentStore({ studioEndpointUrl }).libraries;
const metadata = blockValue?.data?.metadata;
const selectedLibraryId = metadata?.source_library_id;
let selectedLibrary = null;
let selectedLibraryVersion = null;
let blocksInSelectedLibrary = [];
let settings = {};
if (!!selectedLibraryId) {
selectedLibrary = libraries.findIndex(library => {
library.library_key === selectedLibraryId
});
selectedLibraryVersion = api.fetchLibraryProperty({
studioEndpointUrl,
libraryId: selectedLibraryId,
}).version;
settings = {
[selectedLibrary]: {
mode: metadata?.mode,
count: metadata?.count,
showReset: metadata?.allow_resetting_children,
candidates: metadata?.candidates,
},
};
blocksInSelectedLibrary = api.fetchLibraryContent({
studioEndpointUrl,
libraryId: selectedLibraryId,
})?.results;
}
initialize({
libraries,
selectedLibrary,
selectedLibraryId: selectedLibraryId ? selectedLibraryId : null,
selectedLibraryVersion,
settings,
blocksInSelectedLibrary: blocksInSelectedLibrary ? blocksInSelectedLibrary : [],
const useInitialize = () => useEffect(() => {
const libraries = api.fetchContentStore({ studioEndpointUrl }).libraries;
const metadata = blockValue?.data?.metadata;
const selectedLibraryId = metadata?.source_library_id;
let selectedLibrary = null;
let selectedLibraryVersion = null;
let blocksInSelectedLibrary = [];
let settings = {};
if (!!selectedLibraryId) {
selectedLibrary = libraries.findIndex(library => {
library.library_key === selectedLibraryId
});
selectedLibraryVersion = api.fetchLibraryProperty({
studioEndpointUrl,
libraryId: selectedLibraryId,
}).version;
settings = {
[selectedLibrary]: {
mode: metadata?.mode,
count: metadata?.count,
showReset: metadata?.allow_resetting_children,
candidates: metadata?.candidates,
},
};
blocksInSelectedLibrary = api.fetchLibraryContent({
studioEndpointUrl,
libraryId: selectedLibraryId,
})?.results;
}
initialize({
libraries,
selectedLibrary,
selectedLibraryId: selectedLibraryId ? selectedLibraryId : null,
selectedLibraryVersion,
settings,
blocksInSelectedLibrary: blocksInSelectedLibrary ? blocksInSelectedLibrary : [],
});
}, []);

return {
useInitialize,
getContent: () => libraryPayload,
};
};
Expand Down
11 changes: 7 additions & 4 deletions src/editors/containers/LibraryContentEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ export const LibraryContentEditor = ({
console.log("WE GOT THIS FAR");
const {
getContent,
useInitialize,
} = useLibraryHook({
blockFailed,
blockFinished,
blockValue,
initialize,
libraryPayload,
studioEndpointUrl,
});
console.log("WE GOT THIS Hook FAR");

if (blockFinished && !blockFailed) {
useInitialize();
}

const loading = () => (
<div className="text-center p-6">
<Spinner
Expand Down Expand Up @@ -84,6 +87,7 @@ LibraryContentEditor.defaultProps = {
libraryPayload: {},
selectedLibraryId: null,
settings: {},
studioEndpointUrl: '',
};

LibraryContentEditor.propTypes = {
Expand All @@ -95,11 +99,10 @@ LibraryContentEditor.propTypes = {
blockFailed: PropTypes.bool.isRequired,
blockFinished: PropTypes.bool.isRequired,
initialize: PropTypes.func.isRequired,
initializeEditor: PropTypes.func.isRequired,
libraryPayload: PropTypes.shape({}),
selectedLibraryId: PropTypes.string,
settings: PropTypes.shape({}),
studioEndpointUrl: PropTypes.string.isRequired,
studioEndpointUrl: PropTypes.string,
// inject
intl: intlShape.isRequired,
};
Expand Down

0 comments on commit 2674607

Please sign in to comment.