mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 18:36:21 +00:00
feat(frontend) add Activities.tsx
This commit is contained in:
44 files changed
+501
-253
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
|
||||
|
||||
export abstract class Activity {
|
||||
protected constructor(
|
||||
readonly time: Date
|
||||
) {
|
||||
}
|
||||
|
||||
abstract toElement(): React.ReactElement;
|
||||
|
||||
}
|
||||
|
||||
export abstract class GhActivity extends Activity {
|
||||
protected constructor(time: Date) {
|
||||
super(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export const GH_USER_NAME = 'Lumither';
|
||||
@@ -0,0 +1,34 @@
|
||||
import { GhActivity } from '@/src/HomePageActivities/activity';
|
||||
import { Card, CardBody } from '@nextui-org/card';
|
||||
import Link from 'next/link';
|
||||
|
||||
export class StarRepo extends GhActivity {
|
||||
constructor(
|
||||
readonly repoName: string,
|
||||
readonly repoUrl: string,
|
||||
time: Date
|
||||
) {
|
||||
super(time);
|
||||
}
|
||||
|
||||
toElement() {
|
||||
return (
|
||||
// <div>
|
||||
// <Link
|
||||
// href={ this.repoUrl }
|
||||
// >{ `${ GH_USER_NAME } started ${ this.repoName } at ${ this.time }` }</Link>
|
||||
// </div>
|
||||
<Card
|
||||
isHoverable={ true }
|
||||
as={ Link }
|
||||
href={ this.repoUrl }
|
||||
className={ 'bg-black/20' }
|
||||
>
|
||||
<CardBody>
|
||||
<p className={ 'text-sm' }>{ `Stared GitHub repository '${ this.repoName }'` }</p>
|
||||
</CardBody>
|
||||
</Card>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { GhActivity } from '@/src/HomePageActivities/activity';
|
||||
import { match } from 'ts-pattern';
|
||||
import { StarRepo } from '@/src/HomePageActivities/ghActivities/starRepo';
|
||||
import { GH_USER_NAME } from '@/src/HomePageActivities/constants';
|
||||
|
||||
|
||||
export const getGhActivities: () => Promise<GhActivity[]> = async () => {
|
||||
const data = await fetch(`https://api.github.com/users/${ GH_USER_NAME }/events`, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
});
|
||||
return data
|
||||
.json()
|
||||
.then((ret: any): GhActivity[] => (
|
||||
ret
|
||||
.map((res: any) => (
|
||||
match(res)
|
||||
.returnType<GhActivity | undefined>()
|
||||
// star repo
|
||||
.with(
|
||||
{ type: 'WatchEvent', payload: { action: 'started' } }
|
||||
, () => (
|
||||
new StarRepo(res.repo.name, res.repo.url, res.created_at)
|
||||
))
|
||||
// to be continued
|
||||
.otherwise(() => undefined))
|
||||
)
|
||||
.filter((res: GhActivity | undefined) => res !== undefined)
|
||||
));
|
||||
};
|
||||
Reference in new issue
Block a user