-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activity page #1169
base: main
Are you sure you want to change the base?
Activity page #1169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@alexwilson/worker-activity-page", | ||
"private": true, | ||
"version": "0.0.1", | ||
"description": "Activity statistics", | ||
"main": "index.js", | ||
"author": "Alex Wilson <[email protected]>", | ||
"license": "ISC", | ||
"scripts": { | ||
"deploy": "wrangler publish" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^2.0.0", | ||
"@cloudflare/wrangler": "^1.9.1", | ||
"@types/react": "^16.9.44", | ||
"@types/react-dom": "^16.9.8", | ||
"jest": "^26.2.2", | ||
"ts-jest": "^26.1.4", | ||
"ts-loader": "^8.0.2", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.7" | ||
}, | ||
"dependencies": { | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react" | ||
|
||
import Layout from "./layout" | ||
|
||
export const ActivityPage = ({activities}: any) => { | ||
return <Layout title="Activity"> | ||
{activities.map((activity: any) => ( | ||
<React.Fragment key={activity.attribute}> | ||
<h2>{activity.label}</h2> | ||
<ul>{activity.values.map((value: any) => ( | ||
<li key={value.date}>{`${value.date}: ${value.value}`}</li> | ||
))}</ul> | ||
</React.Fragment> | ||
))} | ||
</Layout> | ||
} | ||
|
||
export default ActivityPage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react" | ||
|
||
import Layout from "./layout" | ||
|
||
export const ErrorPage = () => { | ||
return <Layout title="Error!"> | ||
<h1>An error occurred!</h1> | ||
</Layout> | ||
} | ||
|
||
export default ErrorPage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react" | ||
|
||
export const Layout = (props: any) => { | ||
return <html> | ||
<head> | ||
<title>{props.title}</title> | ||
</head> | ||
<body>{props.children}</body> | ||
</html> | ||
} | ||
|
||
export default Layout |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
import {ActivityPage} from "../components/activity-page" | ||||||
import {ErrorPage} from "../components/error-page" | ||||||
|
||||||
export default class Activity { | ||||||
|
||||||
private _existToken: string; | ||||||
|
||||||
constructor(existToken: string) { | ||||||
this._existToken = existToken; | ||||||
} | ||||||
|
||||||
|
||||||
async getActivity() { | ||||||
const query = [ | ||||||
'attributes=events,commits,tweets', | ||||||
'limit=31' | ||||||
] | ||||||
|
||||||
try { | ||||||
const activities = await fetch(`https://exist.io/api/1/users/$self/attributes/?${query.join('&')}`, { | ||||||
method: "GET", | ||||||
headers: { | ||||||
"Authorization": `Token ${this._existToken}`, | ||||||
"Content-Type": "application/json" | ||||||
} | ||||||
}).then(res => res.json()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Expected parentheses around arrow function argument.
Suggested change
|
||||||
|
||||||
return { | ||||||
status: 200, | ||||||
view: ActivityPage({ activities }) | ||||||
} | ||||||
} catch(e) { | ||||||
return { | ||||||
status: 503, | ||||||
view: ErrorPage() | ||||||
} | ||||||
} | ||||||
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
import {renderToString} from "react-dom/server" | ||||||
import ActivityController from "./controllers/activity" | ||||||
|
||||||
const renderToDocument = (component: React.ReactElement): string => `<!DOCTYPE html>${renderToString(component)}` | ||||||
|
||||||
|
||||||
//@ts-ignore | ||||||
const activityController = new ActivityController(EXISTIO_TOKEN) | ||||||
self.addEventListener("fetch", (event) => { | ||||||
event.respondWith(new Promise(async (resolve) => { | ||||||
|
||||||
const result = await activityController.getActivity() | ||||||
resolve(new Response(renderToDocument(result.view), { | ||||||
status: result.status, | ||||||
statusText: "OK", | ||||||
headers: { | ||||||
'content-type': 'text/html' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
} | ||||||
})) | ||||||
|
||||||
})); | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react" | ||
|
||
export const Layout = (props: any) => { | ||
return <html> | ||
<head> | ||
<title>{props.title}</title> | ||
</head> | ||
<body>{props.children}</body> | ||
</html> | ||
} | ||
|
||
export const TestPage = () => { | ||
return <Layout title="test"> | ||
<div>Activity</div> | ||
</Layout> | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"module": "commonjs", | ||
"target": "esnext", | ||
"lib": ["esnext", "webworker"], | ||
"jsx": "react", | ||
"alwaysStrict": true, | ||
"strict": true, | ||
"preserveConstEnums": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"esModuleInterop": true, | ||
"types": ["@cloudflare/workers-types"] | ||
}, | ||
"include": [ | ||
"./src/*.ts", | ||
"./test/*.ts", | ||
"./src/**/*.ts", | ||
"./test/**/*.ts", | ||
"./node_modules/@cloudflare/workers-types/index.d.ts" | ||
], | ||
"exclude": ["node_modules/", "dist/"] | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||
module.exports = { | ||||||
target: "webworker", | ||||||
resolve: { | ||||||
extensions: ['.ts', '.tsx', '.js', '.json'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
}, | ||||||
entry: { | ||||||
main: "./src/index.ts" | ||||||
}, | ||||||
module: { | ||||||
rules: [{ | ||||||
test: /\.tsx?$/, | ||||||
use: 'ts-loader', | ||||||
exclude: /node_modules/, | ||||||
}] | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "activity" | ||
type = "webpack" | ||
routes = ["https://alexwilson.tech/activity"] | ||
webpack_config = "webpack.config.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Missing semicolon.