Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterdev committed Nov 3, 2023
1 parent 67d9252 commit 2a438d0
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ignore
ignore
node_modules
6 changes: 6 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useState as useReactState, useEffect as useReactEffect } from "react";

declare global {
const useState: typeof useReactState;
const useEffect: typeof useReactEffect;
}
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bwe-demos",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/react": "^18.2.34"
}
}
28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/LandingPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
State.init({ isDebug: true, showMonitor: true });
const [isDebug, setIsDebug] = useState<bool>(true);
const [showMonitor, setShowMonitor] = useState<bool>(true);

const buildUrl = (componentPath) => {
return `/${componentPath}?isDebug=${state.isDebug}&showMonitor=${state.showMonitor}`;
return `/${componentPath}?isDebug=${isDebug}&showMonitor=${showMonitor}`;
};

return (
Expand Down Expand Up @@ -49,8 +50,8 @@ return (
type="checkbox"
value=""
id="flexCheckDefault"
checked={state.isDebug}
onChange={() => State.update({ isDebug: !state.isDebug })}
checked={isDebug}
onChange={() => setIsDebug(!isDebug)}
/>
<label className="form-check-label" for="flexCheckDefault">
Enable debug mode
Expand All @@ -62,8 +63,8 @@ return (
type="checkbox"
value=""
id="flexCheckChecked"
checked={state.showMonitor}
onChange={() => State.update({ showMonitor: !state.showMonitor })}
checked={showMonitor}
onChange={() => setShowMonitor(!showMonitor)}
/>
<label className="form-check-label" for="flexCheckChecked">
Display Component monitor
Expand Down
47 changes: 43 additions & 4 deletions src/Posts/Feed.jsx → src/Posts/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
const GRAPHQL_ENDPOINT = "https://near-queryapi.api.pagoda.co";

const [sort, setSort] = useState(null);
const [sort, setSort] = useState("");
const [loading, setLoading] = useState(false);
const [posts, setPosts] = useState([]);
const [posts, setPosts] = useState<Post[]>([]);

async function fetchGraphQL(operationsDoc, operationName, variables) {
interface PostsResponse {
data: {
dataplatform_near_social_feed_moderated_posts: Post[];
dataplatform_near_social_feed_moderated_posts_aggregate: {
aggregate: {
count: number;
};
};
};
}

interface Post {
account_id: string;
block_height: number;
block_timestamp: number;
content: string;
receipt_id: string;
accounts_liked: string[];
last_comment_timestamp: number;
comments: {
account_id: string;
block_height: number;
block_timestamp: string;
content: string;
}[];
verifications: {
human_provider: string;
human_valid_until: string;
human_verification_level: string;
}[];
}

const a = 1;
console.log(a);

async function fetchGraphQL(
operationsDoc,
operationName,
variables
): Promise<PostsResponse> {
const response = await fetch(`${GRAPHQL_ENDPOINT}/v1/graphql`, {
method: "POST",
headers: { "x-hasura-role": "dataplatform_near" },
Expand All @@ -14,7 +53,7 @@ async function fetchGraphQL(operationsDoc, operationName, variables) {
operationName: operationName,
}),
});
const result = await response.json();
const result: PostsResponse = await response.json();
return result;
}

Expand Down

0 comments on commit 2a438d0

Please sign in to comment.