Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tguntenaar committed Dec 11, 2024
1 parent 5aacb6c commit ae0c96a
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 258 deletions.
9 changes: 0 additions & 9 deletions instances/devhub.near/widget/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ function Page() {
/>
);
}
// ?page=feed
// case "feed": {
// return (
// <Widget
// src={"${REPL_DEVHUB}/widget/devhub.page.feed"}
// props={passProps}
// />
// );
// }
// ?page=create
case "create": {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ const MobileMenu = styled.button`
`;

let links = [
// {
// title: "/feed",
// href: "announcements",
// links: [],
// },
{
title: "/communities",
href: "communities",
Expand Down
74 changes: 1 addition & 73 deletions instances/devhub.near/widget/devhub/entity/addon/blog/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,88 +9,16 @@ const Loader = styled.div`
padding: 20px;
`;

const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql/`;
const DISPLAY_COUNT = 10;

const fetchGraphQL = (operationsDoc, operationName, variables) => {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": `bo_near` },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
});
};

const queryName =
props.queryName ?? `bo_near_devhub_v38_posts_with_latest_snapshot`;

const query = `query DevhubPostsQuery($limit: Int = 100, $offset: Int = 0, $where: ${queryName}_bool_exp = {}) {
${queryName}(
limit: $limit
offset: $offset
order_by: {ts: desc}
where: $where
) {
post_id
}
}
`;

const [postIds, setPostIds] = useState([]);
const [loading, setLoading] = useState(false);
const [cachedItems, setCachedItems] = useState({});
const [hasNext, setHasNext] = useState(true);

const buildWhereClause = () => {
let where = {};
if (props.author) {
where = { author_id: { _eq: props.author }, ...where };
}
if (props.term) {
where = { description: { _ilike: `%${props.term}%` }, ...where };
}
if (props.includeLabels && Array.isArray(props.includeLabels)) {
const labelConditions = props.includeLabels.map((label) => ({
labels: { _contains: label },
}));

where = { _and: [...labelConditions, where] };
}
if (props.excludeLabels && Array.isArray(props.excludeLabels)) {
const labelConditions = props.excludeLabels.map((label) => ({
labels: { _nin: label },
}));

where = { _and: [...labelConditions, where] };
}
if (!props.recency) {
where = { parent_id: { _is_null: true }, ...where };
}
return where;
};

const fetchPostIds = (offset) => {
if (!offset) {
offset = 0;
}
if (loading) return;
setLoading(true);
const variables = { limit: DISPLAY_COUNT, offset, where: buildWhereClause() };
// fetchGraphQL(query, "DevhubPostsQuery", variables).then((result) => {
// if (result.status === 200) {
// if (result.body.data) {
// const data = result.body.data[queryName];
// const newPostIds = data.map((p) => p.post_id);
// setPostIds(offset === 0 ? newPostIds : [...postIds, ...newPostIds]);
// setHasNext(data.length >= variables.limit);
// } else {
// console.error("GraphQL Error:", result.errors);
// }
// }
// });

setLoading(false);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,6 @@ const { getPost } = VM.require(

const { Layout, handle } = props;

const includeLabels = ["blog", handle];

const buildWhereClause = () => {
let where = {};
if (props.author) {
where = { author_id: { _eq: props.author }, ...where };
}
if (props.term) {
where = { description: { _ilike: `%${props.term}%` }, ...where };
}
if (includeLabels && Array.isArray(includeLabels)) {
const labelConditions = includeLabels.map((label) => ({
labels: { _contains: label },
}));

where = { _and: [...labelConditions, where] };
}
if (props.excludeLabels && Array.isArray(props.excludeLabels)) {
const labelConditions = props.excludeLabels.map((label) => ({
labels: { _nin: label },
}));

where = { _and: [...labelConditions, where] };
}
if (!props.recency) {
where = { parent_id: { _is_null: true }, ...where };
}
return where;
};

const variables = { limit: DISPLAY_COUNT, offset, where: buildWhereClause() };

const posts = [];

const handleOnChange = (v) => {
Expand Down
139 changes: 0 additions & 139 deletions instances/devhub.near/widget/devhub/entity/post/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,6 @@ if (!href) {
return <p>Loading modules...</p>;
}

const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql/`;

const queryName =
props.queryName ?? `bo_near_devhub_v38_posts_with_latest_snapshot`;
const totalQueryName =
props.totalQueryName ??
"bo_near_devhub_v38_posts_with_latest_snapshot_aggregate";
const query = `query DevhubPostsQuery($limit: Int = 100, $offset: Int = 0, $where: ${queryName}_bool_exp = {}) {
${queryName}(
limit: $limit
offset: $offset
order_by: {ts: desc}
where: $where
) {
post_id
}
}
`;

const totalQuery = `query DevhubTotalPostsQuery($where: ${queryName}_bool_exp = {}) {
${totalQueryName}(
where: $where
) {
aggregate {
count
}
}
}
`;

function fetchGraphQL(operationsDoc, operationName, variables) {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": `bo_near` },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
});
}

function searchConditionChanged() {
return (
props.author != state.author ||
Expand Down Expand Up @@ -83,98 +41,6 @@ State.init({
displayCount: initialRenderLimit,
});

function getPostIds(tag, offset) {
if (searchConditionChanged()) {
updateSearchCondition();
}
let where = {};
let authorId = props.author;
let label = tag || props.tag;
if (authorId) {
where = { author_id: { _eq: authorId }, ...where };
}
if (props.term) {
where = { description: { _ilike: `%${props.term}%` }, ...where };
}
if (label) {
if (typeof label === "string") {
// Handle a single label
where = { labels: { _contains: label }, ...where };
} else if (Array.isArray(label)) {
// Handle an array of labels
where = {
labels: {
_containsAny: label,
},
...where,
};
}
}
if (!props.recency) {
// show only top level posts
where = { parent_id: { _is_null: true }, ...where };
}

// Don't show blog and devhub-test posts
where = {
_and: [
{
_not: {
labels: { _contains: "blog" },
parent_id: { _is_null: true },
post_type: { _eq: "Comment" },
},
},
{
_not: {
labels: { _contains: "devhub-test" },
},
},
],
...where,
};

if (!offset) {
fetchGraphQL(totalQuery, "DevhubTotalPostsQuery", {
where,
}).then((result) => {
const data = result.body.data[totalQueryName];
State.update({
totalItems: data.aggregate.count,
});
});
}

fetchGraphQL(query, "DevhubPostsQuery", {
limit: 50,
offset: offset ?? 0,
where,
}).then((result) => {
if (result.status === 200) {
if (result.body.data) {
const data = result.body.data[queryName];
if (offset) {
State.update({
postIds: state.postIds.concat(data.map((p) => p.post_id)),
loading: false,
});
} else {
State.update({
postIds: data.map((p) => p.post_id),
loading: false,
});
}
}
} else {
State.update({ loading: false });
}
});
}

if (!state.items || searchConditionChanged()) {
// getPostIds();
}

function defaultRenderItem(postId, additionalProps) {
if (!additionalProps) {
additionalProps = {};
Expand All @@ -198,7 +64,6 @@ function defaultRenderItem(postId, additionalProps) {
if (typeof props.updateTagInput === "function") {
props.updateTagInput(tag);
}
// getPostIds(tag);
},
transactionHashes: props.transactionHashes,
}}
Expand Down Expand Up @@ -271,10 +136,7 @@ const initialItems = postIds;

const jInitialItems = JSON.stringify(initialItems);
if (state.jInitialItems !== jInitialItems) {
// const jIndex = JSON.stringify(index);
// if (jIndex !== state.jIndex) {
State.update({
jIndex,
jInitialItems,
items: initialItems,
cachedItems: {},
Expand All @@ -290,7 +152,6 @@ const makeMoreItems = () => {
!state.loading
) {
State.update({ loading: true });
// getPostIds(null, state.items.length);
}
};

Expand Down

0 comments on commit ae0c96a

Please sign in to comment.