Skip to content

Commit

Permalink
Show the total number of users
Browse files Browse the repository at this point in the history
Refs #31
  • Loading branch information
thewilkybarkid committed Jul 4, 2024
1 parent f30697c commit e8ea6b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/data/users.json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Config, Effect, Redacted } from 'effect'

const Users = Schema.Array(Schema.Struct({}))

const program = Effect.gen(function* () {
const terminal = yield* Terminal.Terminal
const token = yield* Config.redacted('PREREVIEW_REVIEWS_DATA_TOKEN')

const request = HttpClientRequest.bearerToken(
HttpClientRequest.get('https://prereview.org/users-data'),
Redacted.value(token),
)

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Users)),
Effect.scoped,
)

const encoded = yield* Schema.encode(Schema.parseJson(Users))(data)

yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
6 changes: 6 additions & 0 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ toc: false
```js
const requests = FileAttachment('./data/requests.json').json()
const reviews = FileAttachment('./data/reviews.json').json()
const users = FileAttachment('./data/users.json').json()
```

<div class="grid grid-cols-4">
Expand All @@ -21,6 +22,11 @@ const reviews = FileAttachment('./data/reviews.json').json()
<h2>Total requests</h2>
<span class="big">${requests.length.toLocaleString("en-US")}</span>
</div>

<div class="card">
<h2>Total users</h2>
<span class="big">${users.length.toLocaleString("en-US")}</span>
</div>
</div>

<style>
Expand Down

0 comments on commit e8ea6b1

Please sign in to comment.