forked from Memmy-App/memmy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add search bar * make button one selectable * selectable is optional * make icon optional for buttonone * adjustable py for button one * button two * start on search screen * scroll to top when pressing feed icon again * search screen with buttons * search, working for communities * push to post * add feeds to search stack * dont use autocomplete or auto cap for search * user profile
- Loading branch information
Showing
10 changed files
with
361 additions
and
47 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
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,80 @@ | ||
import { useEffect, useState } from "react"; | ||
import { | ||
CommentView, | ||
PersonViewSafe, | ||
PostView, | ||
SortType, | ||
} from "lemmy-js-client"; | ||
import { lemmyAuthToken, lemmyInstance } from "../../../lemmy/LemmyInstance"; | ||
import { writeToLog } from "../../../helpers/LogHelper"; | ||
import { useAppSelector } from "../../../store"; | ||
import { selectCurrentAccount } from "../../../slices/accounts/accountsSlice"; | ||
|
||
interface UseProfile { | ||
loading: boolean; | ||
error: boolean; | ||
profile: PersonViewSafe; | ||
posts: PostView[]; | ||
comments: CommentView[]; | ||
doLoad: () => Promise<void>; | ||
self: boolean; | ||
} | ||
|
||
const useProfile = (fullUsername?: string): UseProfile => { | ||
const currentAccount = useAppSelector(selectCurrentAccount); | ||
|
||
const [loading, setLoading] = useState<boolean>(true); | ||
const [error, setError] = useState<boolean>(false); | ||
const [profile, setProfile] = useState<PersonViewSafe>(null); | ||
const [posts, setPosts] = useState<PostView[]>(null); | ||
const [comments, setComments] = useState<CommentView[]>(null); | ||
const [self] = useState(!fullUsername); | ||
|
||
useEffect(() => { | ||
doLoad().then(); | ||
}, []); | ||
|
||
const doLoad = async () => { | ||
let searchUsername = fullUsername; | ||
|
||
if (!fullUsername) { | ||
searchUsername = `${currentAccount.username}@${currentAccount.instance}`; | ||
} | ||
|
||
setLoading(true); | ||
setError(false); | ||
|
||
try { | ||
const res = await lemmyInstance.getPersonDetails({ | ||
auth: lemmyAuthToken, | ||
username: searchUsername, | ||
sort: SortType.New, | ||
limit: 20, | ||
}); | ||
|
||
setProfile(res.person_view); | ||
setComments(res.comments); | ||
setPosts(res.posts); | ||
setLoading(false); | ||
} catch (e) { | ||
writeToLog("Error getting person."); | ||
writeToLog(e.toString()); | ||
|
||
setLoading(false); | ||
setError(true); | ||
} | ||
}; | ||
|
||
return { | ||
loading, | ||
error, | ||
profile, | ||
posts, | ||
comments, | ||
self, | ||
|
||
doLoad, | ||
}; | ||
}; | ||
|
||
export default useProfile; |
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
Oops, something went wrong.