clean up & small fixes
This commit is contained in:
@@ -28,6 +28,10 @@ export function FeedWidgetForm({ params }: { params: Widget }) {
|
||||
setGroups(arr);
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
removeWidget(db, params.id);
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
setWidget(db, {
|
||||
kind: WidgetKinds.feed,
|
||||
@@ -39,7 +43,7 @@ export function FeedWidgetForm({ params }: { params: Widget }) {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-full shrink-0 grow-0 basis-[400px] flex-col items-center justify-center">
|
||||
<div className="flex h-full shrink-0 grow-0 basis-[400px] flex-col items-center justify-center bg-white/10">
|
||||
<div className="w-full px-5">
|
||||
<h3 className="mb-4 text-center text-lg font-semibold">
|
||||
Choose account you want to add to group feeds
|
||||
@@ -70,7 +74,7 @@ export function FeedWidgetForm({ params }: { params: Widget }) {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center justify-center">
|
||||
<div className="flex flex-col items-center justify-center gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={groups.length < 1}
|
||||
@@ -81,6 +85,13 @@ export function FeedWidgetForm({ params }: { params: Widget }) {
|
||||
<span>Add {groups.length} account to group feed</span>
|
||||
<ArrowRightCircleIcon className="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={cancel}
|
||||
className="inline-flex h-11 w-full items-center justify-center gap-2 rounded-lg bg-white/10 px-6 font-medium leading-none text-white hover:bg-white/20 focus:outline-none disabled:opacity-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -40,6 +40,10 @@ export function HashTagWidgetForm({ params }: { params: Widget }) {
|
||||
formState: { errors, isDirty, isValid },
|
||||
} = useForm<FormValues>({ resolver });
|
||||
|
||||
const cancel = () => {
|
||||
removeWidget(db, params.id);
|
||||
};
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
try {
|
||||
setWidget(db, {
|
||||
@@ -58,7 +62,7 @@ export function HashTagWidgetForm({ params }: { params: Widget }) {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-full shrink-0 grow-0 basis-[400px] flex-col items-center justify-center">
|
||||
<div className="flex h-full shrink-0 grow-0 basis-[400px] flex-col items-center justify-center bg-white/10">
|
||||
<div className="w-full px-5">
|
||||
<h3 className="mb-4 text-center text-lg font-semibold">
|
||||
Enter hashtag you want to follow
|
||||
@@ -74,7 +78,7 @@ export function HashTagWidgetForm({ params }: { params: Widget }) {
|
||||
{errors.hashtag && <p>{errors.hashtag.message}</p>}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-center">
|
||||
<div className="flex flex-col items-center justify-center gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!isDirty || !isValid}
|
||||
@@ -84,6 +88,13 @@ export function HashTagWidgetForm({ params }: { params: Widget }) {
|
||||
<span>Create</span>
|
||||
<ArrowRightCircleIcon className="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={cancel}
|
||||
className="inline-flex h-11 w-full items-center justify-center gap-2 rounded-lg bg-white/10 px-6 font-medium leading-none text-white hover:bg-white/20 focus:outline-none disabled:opacity-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { FollowIcon, LoaderIcon, UnfollowIcon } from '@shared/icons';
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
import { FollowIcon, UnfollowIcon } from '@shared/icons';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { useSocial } from '@utils/hooks/useSocial';
|
||||
import { useNostr } from '@utils/hooks/useNostr';
|
||||
import { compactNumber } from '@utils/number';
|
||||
import { shortenKey } from '@utils/shortenKey';
|
||||
|
||||
@@ -14,7 +16,8 @@ export interface Profile {
|
||||
}
|
||||
|
||||
export function UserProfile({ data }: { data: Profile }) {
|
||||
const { status: socialStatus, userFollows, follow, unfollow } = useSocial();
|
||||
const { db } = useStorage();
|
||||
const { addContact, removeContact } = useNostr();
|
||||
const { status, data: userStats } = useQuery(
|
||||
['user-stats', data.pubkey],
|
||||
async () => {
|
||||
@@ -36,7 +39,7 @@ export function UserProfile({ data }: { data: Profile }) {
|
||||
|
||||
const followUser = (pubkey: string) => {
|
||||
try {
|
||||
follow(pubkey);
|
||||
addContact(pubkey);
|
||||
// update state
|
||||
setFollowed(true);
|
||||
} catch (error) {
|
||||
@@ -46,7 +49,7 @@ export function UserProfile({ data }: { data: Profile }) {
|
||||
|
||||
const unfollowUser = (pubkey: string) => {
|
||||
try {
|
||||
unfollow(pubkey);
|
||||
removeContact(pubkey);
|
||||
// update state
|
||||
setFollowed(false);
|
||||
} catch (error) {
|
||||
@@ -55,12 +58,10 @@ export function UserProfile({ data }: { data: Profile }) {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (status === 'success' && userFollows) {
|
||||
if (userFollows.includes(data.pubkey)) {
|
||||
setFollowed(true);
|
||||
}
|
||||
if (db.account.follows.includes(data.pubkey)) {
|
||||
setFollowed(true);
|
||||
}
|
||||
}, [status]);
|
||||
}, []);
|
||||
|
||||
if (!profile) {
|
||||
return (
|
||||
@@ -88,14 +89,7 @@ export function UserProfile({ data }: { data: Profile }) {
|
||||
</div>
|
||||
</div>
|
||||
<div className="inline-flex items-center gap-2">
|
||||
{socialStatus === 'loading' ? (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-white/10 hover:bg-fuchsia-500"
|
||||
>
|
||||
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
||||
</button>
|
||||
) : followed ? (
|
||||
{followed ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => unfollowUser(data.pubkey)}
|
||||
|
||||
Reference in New Issue
Block a user