-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shuaige1234567
committed
Dec 12, 2023
1 parent
dbdc6d4
commit c9564e1
Showing
11 changed files
with
167 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Principal} from "@dfinity/principal"; | ||
import {idlFactory} from "../declarations/bucket/bucket.did.js"; | ||
import {getActor} from "../utils/Actor"; | ||
import {PostImmutable} from "../declarations/bucket/bucket"; | ||
|
||
|
||
export default class Bucket { | ||
|
||
private readonly canisterId: Principal; | ||
|
||
constructor(canisterId: Principal) { | ||
this.canisterId = canisterId; | ||
} | ||
|
||
private async getActor() { | ||
return await getActor.createActor(idlFactory, this.canisterId.toString()); | ||
} | ||
|
||
async getLatestFeed(n: number) { | ||
const actor = await this.getActor() | ||
try { | ||
return await actor.getLatestFeed(BigInt(n)) as PostImmutable[] | ||
} catch (e) { | ||
console.log("getLatestFeed", e) | ||
throw e | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {getActor} from "../utils/Actor"; | ||
import {idlFactory} from "../declarations/rootPost/rootPost.did.js" | ||
import {Principal} from "@dfinity/principal"; | ||
|
||
const rootPostCai = "lyksr-aiaaa-aaaan-qgj2q-cai" | ||
|
||
class rootPost { | ||
private static async getActor() { | ||
return await getActor.createActor(idlFactory, rootPostCai); | ||
} | ||
|
||
async getAvailableBucket() { | ||
const actor = await rootPost.getActor() | ||
try { | ||
return await actor.getAvailableBucket() as [] | [Principal] | ||
} catch (e) { | ||
console.log("getAvailableBucket", e) | ||
throw e | ||
} | ||
} | ||
} | ||
|
||
export const rootPostApi = new rootPost() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
import {Content} from "./content"; | ||
import React from "react"; | ||
import React, {useEffect, useState} from "react"; | ||
import {rootPostApi} from "../actors/rootPost"; | ||
import Bucket from "../actors/bucket"; | ||
import {PostImmutable} from "../declarations/feed/feed"; | ||
|
||
export default function Explore() { | ||
return <Content contents={[]}/> | ||
const [contents, setContents] = useState<PostImmutable[]>([]) | ||
|
||
const fetch = async () => { | ||
const bucket = await rootPostApi.getAvailableBucket() | ||
if (!bucket[0]) return | ||
const bucketApi = new Bucket(bucket[0]) | ||
const res = await bucketApi.getLatestFeed(30) | ||
setContents(res) | ||
} | ||
|
||
useEffect(() => { | ||
fetch() | ||
}, []) | ||
|
||
return <Content contents={contents}/> | ||
} |