Skip to content

Commit

Permalink
feat: use await/async function
Browse files Browse the repository at this point in the history
  • Loading branch information
andyhuang18 committed Oct 21, 2023
1 parent ced0589 commit 5985749
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function getUserOrOrgRepos(
}

// TODO 需要找到一个合适的方法解决Token的问题...
const accessToken = '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';
const accessToken = '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';

const columns: ColumnsType<DataType> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,7 @@ export const CollectionManageModal = () => {

useEffect(() => {}, []);

const onCreate = (values: any, newRepoData: string[] | undefined) => {
/*
* remove collection and its relations
*/
if (selectedCollection) {
updaters.removeCollection(selectedCollection);
updaters.removeRelations(
allRelations.filter(
(relation) => relation.collectionId === selectedCollection
)
);
}

/*
* add newCollection and its relations
*/
setSelectedCollection(values.collectionName);
if (newRepoData) {
updaters.addCollection(values.collectionName);
updaters.addRelations(
newRepoData.map((repo) => ({
collectionId: values.collectionName,
repositoryId: repo,
}))
);
}

setListData(newRepoData);
const onCreate = async (values: any, newRepoData: string[] | undefined) => {
if (isEdit) {
const updatedItems = items.map((item) => {
if (item.key === activeKey?.toString()) {
Expand All @@ -123,8 +96,41 @@ export const CollectionManageModal = () => {
setItems(newPanes);
setActiveKey(values.collectionName);
}

try {
/*
* remove collection and its relations
*/
if (selectedCollection) {
await updaters.removeCollection(selectedCollection);
const relationsToRemove = allRelations.filter(
(relation) => relation.collectionId === selectedCollection
);
await updaters.removeRelations(relationsToRemove);
}

/*
* add newCollection and its relations
*/

await updaters.addCollection({
id: values.collectionName,
name: values.collectionName,
});
if (newRepoData) {
const relationsToAdd = newRepoData.map((repo) => ({
collectionId: values.collectionName,
repositoryId: repo,
}));
await updaters.addRelations(relationsToAdd);
}
} catch (error) {
console.error('Error:', error);
}
console.log('Received values of form: ', values);

setListData(newRepoData);
setSelectedCollection(values.collectionName);
setIsClick(false);
setIsEdit(undefined);
};
Expand Down

0 comments on commit 5985749

Please sign in to comment.