Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getTagsCommand = commandFactory(async ({ path }) => {
const response = await fetch(`${baseUrl}/tags`);
const json = await response.json();
return [replace(path("tags"), json.tags)];
});
async ({ get, path, payload: { username } }) => {
const token = get(path("session", "token"));
const response = await fetch(`${baseUrl}/profiles/${username}`, {
headers: getHeaders(token)
});
const json = await response.json();
return [
replace(path("profile", "user", "username"), json.profile.username),
replace(path("profile", "user", "image"), json.profile.image),
replace(path("profile", "user", "bio"), json.profile.bio),
replace(path("profile", "user", "following"), json.profile.following),
replace(path("profile", "user", "isLoading"), false),
replace(path("profile", "user", "isLoaded"), true)
];
}
);
const deleteArticleCommand = commandFactory(async ({ get, path, payload: { slug } }) => {
const token = get(path("session", "token"));
await fetch(`${baseUrl}/articles/${slug}`, {
method: "delete",
headers: getHeaders(token)
});
return [replace(path("routing", "outlet"), "home")];
});
const filterOptions = get(path(id, 'meta', 'filter'));
let result: FetcherResult[];
try {
const options = {
sort: { columnId, direction },
filter: filterOptions
};
const previousPage = fetcher(page - 1, pageSize, options);
const currentPage = fetcher(page, pageSize, options);
result = await Promise.all([previousPage, currentPage]);
} catch (err) {
return [];
}
return [
replace(path(id, 'data', 'pages', `page-${page - 1}`), result[0].data),
replace(path(id, 'data', 'pages', `page-${page}`), result[1].data),
replace(path(id, 'meta', 'sort', 'columnId'), columnId),
replace(path(id, 'meta', 'sort', 'direction'), direction),
replace(path(id, 'meta', 'total'), result[1].meta.total),
replace(path(id, 'meta', 'page'), page),
replace(path(id, 'meta', 'isSorting'), false)
];
}
);
const bodyInputCommand = commandFactory(({ path, payload: { body } }) => {
return [replace(path("editor", "body"), body)];
});
async ({ at, path, get, payload: { id, updater, columnId, value, page, rowNumber } }) => {
const item = get(at(path(id, 'data', 'pages', `page-${page}`), rowNumber));
try {
await updater(item);
} catch (err) {
const previousItem = get(path(id, 'meta', 'editedRow', 'item'));
return [
replace(at(path(id, 'data', 'pages', `page-${page}`), rowNumber), previousItem)
];
}
return [replace(path(id, 'meta', 'editedRow'), undefined)];
}
);
const emailInputCommand = commandFactory(({ payload: { email }, path }) => {
return [replace(path('settings', 'email'), email)];
});
const loginEmailInputCommand = commandFactory(({ path, payload: { email } }) => {
return [replace(path('login', 'email'), email)];
});
url = `${baseUrl}/articles/feed?`;
break;
case "tag":
url = `${baseUrl}/articles?tag=${filter}&`;
break;
default:
url = `${baseUrl}/articles/?`;
break;
}
const response = await fetch(`${url}limit=10&offset=${offset}`, { headers: getHeaders(token) });
const json = await response.json();
return [
replace(path("feed", "items"), json.articles),
replace(path("feed", "total"), json.articlesCount),
replace(path("feed", "offset"), offset),
replace(path("feed", "page"), page),
replace(path("feed", "category"), type),
replace(path("feed", "filter"), filter),
replace(path("feed", "isLoading"), false),
replace(path("feed", "isLoaded"), true)
];
}
);
const requestPayload = {
comment: {
body: newComment
}
};
const response = await fetch(`${baseUrl}/articles/${slug}/comments`, {
method: "post",
headers: getHeaders(token),
body: JSON.stringify(requestPayload)
});
const json = await response.json();
const comments = get(path("article", slug, "comments"));
return [
replace(path("article", slug, "comments"), [...comments, json.comment]),
replace(path("article", slug, "newComment"), "")
];
});