mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
Remove useChannel
This commit is contained in:
@@ -13,7 +13,7 @@ import { useContext, useEffect, useMemo, useState } from "preact/hooks";
|
||||
|
||||
import { internalSubscribe } from "../../lib/eventEmitter";
|
||||
|
||||
import { User } from "../../mobx";
|
||||
import { Channel, User } from "../../mobx";
|
||||
|
||||
import { Action } from "../../components/ui/Modal";
|
||||
|
||||
@@ -34,15 +34,15 @@ export type Screen =
|
||||
actions: Action[];
|
||||
}
|
||||
| ({ id: "special_prompt" } & (
|
||||
| { type: "leave_group"; target: Channels.GroupChannel }
|
||||
| { type: "close_dm"; target: Channels.DirectMessageChannel }
|
||||
| { type: "leave_group"; target: Channel }
|
||||
| { type: "close_dm"; target: Channel }
|
||||
| { type: "leave_server"; target: Servers.Server }
|
||||
| { type: "delete_server"; target: Servers.Server }
|
||||
| { type: "delete_channel"; target: Channels.TextChannel }
|
||||
| { type: "delete_channel"; target: Channel }
|
||||
| { type: "delete_message"; target: Channels.Message }
|
||||
| {
|
||||
type: "create_invite";
|
||||
target: Channels.TextChannel | Channels.GroupChannel;
|
||||
target: Channel;
|
||||
}
|
||||
| { type: "kick_member"; target: Servers.Server; user: User }
|
||||
| { type: "ban_member"; target: Servers.Server; user: User }
|
||||
@@ -83,7 +83,7 @@ export type Screen =
|
||||
| { id: "image_viewer"; attachment?: Attachment; embed?: EmbedImage }
|
||||
| { id: "modify_account"; field: "username" | "email" | "password" }
|
||||
| { id: "profile"; user_id: string }
|
||||
| { id: "channel_info"; channel_id: string }
|
||||
| { id: "channel_info"; channel: Channel }
|
||||
| { id: "pending_requests"; users: User[] }
|
||||
| {
|
||||
id: "user_picker";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useContext, useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { TextReact } from "../../../lib/i18n";
|
||||
|
||||
import { User } from "../../../mobx";
|
||||
import { Channel, User } from "../../../mobx";
|
||||
import { useData } from "../../../mobx/State";
|
||||
|
||||
import Message from "../../../components/common/messaging/Message";
|
||||
@@ -55,15 +55,15 @@ export function PromptModal({
|
||||
}
|
||||
|
||||
type SpecialProps = { onClose: () => void } & (
|
||||
| { type: "leave_group"; target: Channels.GroupChannel }
|
||||
| { type: "close_dm"; target: Channels.DirectMessageChannel }
|
||||
| { type: "leave_group"; target: Channel }
|
||||
| { type: "close_dm"; target: Channel }
|
||||
| { type: "leave_server"; target: Servers.Server }
|
||||
| { type: "delete_server"; target: Servers.Server }
|
||||
| { type: "delete_channel"; target: Channels.TextChannel }
|
||||
| { type: "delete_channel"; target: Channel }
|
||||
| { type: "delete_message"; target: Channels.Message }
|
||||
| {
|
||||
type: "create_invite";
|
||||
target: Channels.TextChannel | Channels.GroupChannel;
|
||||
target: Channel;
|
||||
}
|
||||
| { type: "kick_member"; target: Servers.Server; user: User }
|
||||
| { type: "ban_member"; target: Servers.Server; user: User }
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { X } from "@styled-icons/boxicons-regular";
|
||||
import { observer } from "mobx-react-lite";
|
||||
|
||||
import styles from "./ChannelInfo.module.scss";
|
||||
|
||||
import { Channel } from "../../../mobx";
|
||||
|
||||
import Modal from "../../../components/ui/Modal";
|
||||
|
||||
import Markdown from "../../../components/markdown/Markdown";
|
||||
import { useChannel, useForceUpdate } from "../../revoltjs/hooks";
|
||||
import { useClient } from "../../revoltjs/RevoltClient";
|
||||
import { useForceUpdate } from "../../revoltjs/hooks";
|
||||
import { getChannelName } from "../../revoltjs/util";
|
||||
|
||||
interface Props {
|
||||
channel_id: string;
|
||||
channel: Channel;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function ChannelInfo({ channel_id, onClose }: Props) {
|
||||
const ctx = useForceUpdate();
|
||||
const channel = useChannel(channel_id, ctx);
|
||||
if (!channel) return null;
|
||||
|
||||
export const ChannelInfo = observer(({ channel, onClose }: Props) => {
|
||||
if (
|
||||
channel.channel_type === "DirectMessage" ||
|
||||
channel.channel_type === "SavedMessages"
|
||||
@@ -26,19 +26,20 @@ export function ChannelInfo({ channel_id, onClose }: Props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const client = useClient();
|
||||
return (
|
||||
<Modal visible={true} onClose={onClose}>
|
||||
<div className={styles.info}>
|
||||
<div className={styles.header}>
|
||||
<h1>{getChannelName(ctx.client, channel, true)}</h1>
|
||||
<h1>{getChannelName(client, channel, true)}</h1>
|
||||
<div onClick={onClose}>
|
||||
<X size={36} />
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<Markdown content={channel.description} />
|
||||
<Markdown content={channel.description!} />
|
||||
</p>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -27,11 +27,7 @@ import {
|
||||
StatusContext,
|
||||
useClient,
|
||||
} from "../../revoltjs/RevoltClient";
|
||||
import {
|
||||
useChannels,
|
||||
useForceUpdate,
|
||||
useUserPermission,
|
||||
} from "../../revoltjs/hooks";
|
||||
import { useForceUpdate, useUserPermission } from "../../revoltjs/hooks";
|
||||
import { useIntermediate } from "../Intermediate";
|
||||
|
||||
interface Props {
|
||||
@@ -65,7 +61,6 @@ export function UserProfile({ user_id, onClose, dummy, dummyProfile }: Props) {
|
||||
const [tab, setTab] = useState("profile");
|
||||
|
||||
const ctx = useForceUpdate();
|
||||
const channels = useChannels(undefined, ctx);
|
||||
const permissions = useUserPermission(client.user!._id, ctx);
|
||||
|
||||
const store = useData();
|
||||
@@ -77,6 +72,12 @@ export function UserProfile({ user_id, onClose, dummy, dummyProfile }: Props) {
|
||||
const user = store.users.get(user_id)!;
|
||||
const users = mutual?.users.map((id) => store.users.get(id));
|
||||
|
||||
const mutualGroups = [...store.channels.values()].filter(
|
||||
(channel) =>
|
||||
channel?.channel_type === "Group" &&
|
||||
channel.recipients!.includes(user_id),
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!user_id) return;
|
||||
if (typeof profile !== "undefined") setProfile(undefined);
|
||||
@@ -111,12 +112,6 @@ export function UserProfile({ user_id, onClose, dummy, dummyProfile }: Props) {
|
||||
}
|
||||
}, [profile, status]);
|
||||
|
||||
const mutualGroups = channels.filter(
|
||||
(channel) =>
|
||||
channel?.channel_type === "Group" &&
|
||||
channel.recipients.includes(user_id),
|
||||
);
|
||||
|
||||
const backgroundURL =
|
||||
profile &&
|
||||
client.users.getBackgroundURL(profile, { width: 1000 }, true);
|
||||
|
||||
Reference in New Issue
Block a user