Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuanxun committed Dec 13, 2023
1 parent 22a29e3 commit 70b1723
Show file tree
Hide file tree
Showing 54 changed files with 242 additions and 74 deletions.
3 changes: 3 additions & 0 deletions frontend/src/components/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {useAuth} from "../utils/useAuth";
import Feed from "../actors/feed";
import React, {useEffect, useState} from "react";
import {CommentForm} from "./Modal/commentForm";
import {useNavigate} from "react-router-dom";

export default function Post(props: { content: PostImmutable, setPostItem?: Function, avatar?: string, name?: string }) {
const {content, setPostItem} = props
Expand All @@ -19,6 +20,7 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
useEffect(() => {
setData(content)
}, [content])
const navigate = useNavigate();

const feedApi = React.useMemo(() => {
if (!userFeedCai) return undefined
Expand Down Expand Up @@ -58,6 +60,7 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
}} onClick={() => setPostItem?.(data)}>
<Space>
<Avatar
onClick={() => navigate(`/profile/${content.user.toString()}`)}
size={32}
src={props.avatar ? props.avatar : "https://avatars.githubusercontent.com/u/120618331?s=200&v=4"}
style={{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/bucket/bucket.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/bucket/bucket.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
const PostId = IDL.Text;
const PostImmutable = IDL.Record({
'repost' : IDL.Vec(Repost),
'title' : IDL.Text,
'content' : IDL.Text,
'like' : IDL.Vec(Like),
'createdAt' : Time,
'user' : UserId,
'comment' : IDL.Vec(Comment),
'index' : IDL.Nat,
'feedCanister' : IDL.Principal,
'postId' : PostId,
});
const NewComment = IDL.Vec(Comment);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/bucket/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export type NewRepost = Array<Repost>;
export type PostId = string;
export interface PostImmutable {
'repost' : Array<Repost>,
'title' : string,
'content' : string,
'like' : Array<Like>,
'createdAt' : Time,
'user' : UserId,
'comment' : Array<Comment>,
'index' : bigint,
'feedCanister' : Principal,
'postId' : PostId,
}
export interface Repost { 'createdAt' : Time, 'user' : UserId }
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/bucket/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { Principal } from "@dfinity/principal";
import type { IDL } from "@dfinity/candid";

import { _SERVICE } from './bucket';
import { _SERVICE } from './bucket.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/commentFetch/commentFetch.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface Like { 'createdAt' : Time, 'user' : UserId }
export type PostId = string;
export interface PostImmutable {
'repost' : Array<Repost>,
'title' : string,
'content' : string,
'like' : Array<Like>,
'createdAt' : Time,
'user' : UserId,
'comment' : Array<Comment>,
'index' : bigint,
'feedCanister' : Principal,
'postId' : PostId,
}
export interface Repost { 'createdAt' : Time, 'user' : UserId }
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/commentFetch/commentFetch.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
const PostId = IDL.Text;
const PostImmutable = IDL.Record({
'repost' : IDL.Vec(Repost),
'title' : IDL.Text,
'content' : IDL.Text,
'like' : IDL.Vec(Like),
'createdAt' : Time,
'user' : UserId,
'comment' : IDL.Vec(Comment),
'index' : IDL.Nat,
'feedCanister' : IDL.Principal,
'postId' : PostId,
});
const CommentFetch = IDL.Service({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/feed/feed.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/feed/feed.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
const PostId = IDL.Text;
const PostImmutable = IDL.Record({
'repost' : IDL.Vec(Repost),
'title' : IDL.Text,
'content' : IDL.Text,
'like' : IDL.Vec(Like),
'createdAt' : Time,
'user' : UserId,
'comment' : IDL.Vec(Comment),
'index' : IDL.Nat,
'feedCanister' : IDL.Principal,
'postId' : PostId,
});
const Feed = IDL.Service({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/feed/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export interface Like { 'createdAt' : Time, 'user' : UserId }
export type PostId = string;
export interface PostImmutable {
'repost' : Array<Repost>,
'title' : string,
'content' : string,
'like' : Array<Like>,
'createdAt' : Time,
'user' : UserId,
'comment' : Array<Comment>,
'index' : bigint,
'feedCanister' : Principal,
'postId' : PostId,
}
export interface Repost { 'createdAt' : Time, 'user' : UserId }
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/feed/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { Principal } from "@dfinity/principal";
import type { IDL } from "@dfinity/candid";

import { _SERVICE } from './feed';
import { _SERVICE } from './feed.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/likeFetch/likeFetch.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/likeFetch/likeFetch.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface LikeFetch {
export type PostId = string;
export interface PostImmutable {
'repost' : Array<Repost>,
'title' : string,
'content' : string,
'like' : Array<Like>,
'createdAt' : Time,
'user' : UserId,
'comment' : Array<Comment>,
'index' : bigint,
'feedCanister' : Principal,
'postId' : PostId,
}
export interface Repost { 'createdAt' : Time, 'user' : UserId }
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/likeFetch/likeFetch.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
const PostId = IDL.Text;
const PostImmutable = IDL.Record({
'repost' : IDL.Vec(Repost),
'title' : IDL.Text,
'content' : IDL.Text,
'like' : IDL.Vec(Like),
'createdAt' : Time,
'user' : UserId,
'comment' : IDL.Vec(Comment),
'index' : IDL.Nat,
'feedCanister' : IDL.Principal,
'postId' : PostId,
});
const LikeFetch = IDL.Service({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/rootFeed/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { Principal } from "@dfinity/principal";
import type { IDL } from "@dfinity/candid";

import { _SERVICE } from './rootFeed';
import { _SERVICE } from './rootFeed.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/declarations/rootPost/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { Principal } from "@dfinity/principal";
import type { IDL } from "@dfinity/candid";

import { _SERVICE } from './rootPost';
import { _SERVICE } from './rootPost.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/rootPost/rootPost.did
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type RootPost =
service {
addAvailBucket: (vec principal) -> ();
createBucket: () -> (principal);
getAllAvailableBuckets: () -> (vec principal) query;
getAllBuckets: () -> (vec principal) query;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/rootPost/rootPost.did.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const idlFactory = ({ IDL }) => {
const RootPost = IDL.Service({
'addAvailBucket' : IDL.Func([IDL.Vec(IDL.Principal)], [], []),
'createBucket' : IDL.Func([], [IDL.Principal], []),
'getAllAvailableBuckets' : IDL.Func(
[],
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/rootPost/rootPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';

export interface RootPost {
'addAvailBucket' : ActorMethod<[Array<Principal>], undefined>,
'createBucket' : ActorMethod<[], Principal>,
'getAllAvailableBuckets' : ActorMethod<[], Array<Principal>>,
'getAllBuckets' : ActorMethod<[], Array<Principal>>,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/user/user.did
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type User =
getProfile: (UserId__1) -> (opt Profile) query;
getRootFeedCanister: () -> (principal) query;
init: (principal) -> () oneway;
isFollowed: (Vertex, Vertex) -> (bool) query;
searchProfile: (text) -> (vec Profile) query;
updateProfile: (NewProfile) -> ();
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/user/user.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const idlFactory = ({ IDL }) => {
'getProfile' : IDL.Func([UserId__1], [IDL.Opt(Profile)], ['query']),
'getRootFeedCanister' : IDL.Func([], [IDL.Principal], ['query']),
'init' : IDL.Func([IDL.Principal], [], ['oneway']),
'isFollowed' : IDL.Func([Vertex, Vertex], [IDL.Bool], ['query']),
'searchProfile' : IDL.Func([IDL.Text], [IDL.Vec(Profile)], ['query']),
'updateProfile' : IDL.Func([NewProfile], [], []),
});
Expand Down
1 change: 1 addition & 0 deletions frontend/src/declarations/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface User {
'getProfile' : ActorMethod<[UserId__1], [] | [Profile]>,
'getRootFeedCanister' : ActorMethod<[], Principal>,
'init' : ActorMethod<[Principal], undefined>,
'isFollowed' : ActorMethod<[Vertex, Vertex], boolean>,
'searchProfile' : ActorMethod<[string], Array<Profile>>,
'updateProfile' : ActorMethod<[NewProfile], undefined>,
}
Expand Down
24 changes: 20 additions & 4 deletions frontend/src/routes/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useEffect} from 'react';
import {Layout, Image, Typography, Avatar, Flex, Space, Button, Modal, message, Spin} from 'antd';
import {Layout, Image, Typography, Avatar, Flex, Space, Button, Modal, message, notification, Spin} from 'antd';
import Post from '../components/post';
import {userApi} from '../actors/user';
import {Profile} from '../declarations/user/user';
Expand All @@ -12,6 +12,8 @@ import {rootFeedApi} from "../actors/rootFeed";
import Feed from "../actors/feed";
import {useAllDataStore, useProfileStore} from "../redux";
import {useAuth} from "../utils/useAuth";
import { LoadingOutlined, CheckOutlined } from '@ant-design/icons';


export default function UserProfile() {
const {principal: me} = useAuth()
Expand All @@ -23,6 +25,7 @@ export default function UserProfile() {
const [following, setFollowing] = useState(0)
const [followers, setFollowers] = useState(0)
const [allPosts, setAllPosts] = useState<PostImmutable[]>()
const [api, contextHolder] = notification.useNotification();
const {userid} = useParams()
const [commentProfiles, setCommentProfiles] = useState<Profile[]>()
const [commentLoading, setCommentLoading] = useState(true)
Expand Down Expand Up @@ -99,12 +102,25 @@ export default function UserProfile() {
setIsModalOpen(true);
};

const handleClick = async () => {
const handleFollow = async () => {
if (isMe) {
handleEditProfile()
} else {
if (!principal) return
userApi.follow(principal).then()
api.info({
message: 'Follow ing ...',
key: 'follow',
duration: null,
description: '',
icon: <LoadingOutlined />
})
await userApi.follow(principal);
api.success({
message: 'Follow Successful !',
key: 'follow',
description: '',
icon: <CheckOutlined />
});
}
}

Expand Down Expand Up @@ -143,7 +159,7 @@ export default function UserProfile() {
/>
<Typography.Text strong>{userProfile?.name}</Typography.Text>
</Space>
<Button onClick={handleClick}> {isMe ? "Edit Profile" : "Follow"} </Button>
<Button onClick={handleFollow}> {isMe ? "Edit Profile" : "Follow"} </Button>
<Modal
title="Edit Profile Information"
open={isModalOpen}
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/bucket/bucket.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/bucket/bucket.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export type NewRepost = Array<Repost>;
export type PostId = string;
export interface PostImmutable {
'repost' : Array<Repost>,
'title' : string,
'content' : string,
'like' : Array<Like>,
'createdAt' : Time,
'user' : UserId,
'comment' : Array<Comment>,
'index' : bigint,
'feedCanister' : Principal,
'postId' : PostId,
}
export interface Repost { 'createdAt' : Time, 'user' : UserId }
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/bucket/bucket.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
const PostId = IDL.Text;
const PostImmutable = IDL.Record({
'repost' : IDL.Vec(Repost),
'title' : IDL.Text,
'content' : IDL.Text,
'like' : IDL.Vec(Like),
'createdAt' : Time,
'user' : UserId,
'comment' : IDL.Vec(Comment),
'index' : IDL.Nat,
'feedCanister' : IDL.Principal,
'postId' : PostId,
});
const NewComment = IDL.Vec(Comment);
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/commentFetch/commentFetch.did
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type PostImmutable =
comment: vec Comment;
content: text;
createdAt: Time;
feedCanister: principal;
index: nat;
like: vec Like;
postId: PostId;
repost: vec Repost;
title: text;
user: UserId;
};
type PostId = text;
Expand Down
Loading

0 comments on commit 70b1723

Please sign in to comment.