Compare commits
No commits in common. "44c9e55928a0a47c59b148f7c173dc47543e9250" and "cd1ae210e7667d9f9acffa8c9aa8389352a9d8ae" have entirely different histories.
44c9e55928
...
cd1ae210e7
7 changed files with 72 additions and 215 deletions
|
@ -1,5 +0,0 @@
|
||||||
.SizedTextarea {
|
|
||||||
overflow-y: hidden;
|
|
||||||
width: 100%;
|
|
||||||
resize: vertical;
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
import { splitProps, type Component, type JSX } from "solid-js";
|
|
||||||
import "./SizedTextarea.css";
|
|
||||||
|
|
||||||
function isBoundEventHandler<T, E extends Event>(
|
|
||||||
handler: JSX.EventHandlerUnion<T, E>,
|
|
||||||
): handler is JSX.BoundEventHandler<T, E> {
|
|
||||||
return Array.isArray(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
function callEventHandlerUnion<T extends EventTarget, E extends Event>(
|
|
||||||
handler: JSX.EventHandlerUnion<T, E>,
|
|
||||||
event: E & { currentTarget: T; target: Element },
|
|
||||||
) {
|
|
||||||
if (isBoundEventHandler(handler)) {
|
|
||||||
const fn = handler[0],
|
|
||||||
value = handler[1];
|
|
||||||
fn(value, event);
|
|
||||||
} else {
|
|
||||||
(handler as (e: typeof event) => void).bind(event.target)(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTextareaRefreshHeight<
|
|
||||||
E extends Event & {
|
|
||||||
currentTarget: HTMLTextAreaElement;
|
|
||||||
target: HTMLTextAreaElement;
|
|
||||||
},
|
|
||||||
>(
|
|
||||||
ocallback: JSX.EventHandlerUnion<HTMLTextAreaElement, E> | undefined,
|
|
||||||
event: E,
|
|
||||||
) {
|
|
||||||
const element = event.currentTarget;
|
|
||||||
element.style.removeProperty("height");
|
|
||||||
element.style.height = `${element.scrollHeight + 2}px`;
|
|
||||||
|
|
||||||
if (ocallback) {
|
|
||||||
callEventHandlerUnion(ocallback, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <textarea /> automatically vertically sized as the content.
|
|
||||||
*
|
|
||||||
* Note: listens the "focus" and "input" event using `addEventListener()`
|
|
||||||
* may not work - use the event listening syntax on the component instead.
|
|
||||||
* If you find it work, tell Rubicon to remove this note.
|
|
||||||
*/
|
|
||||||
const SizedTextarea: Component<JSX.HTMLElementTags["textarea"]> = (oprops) => {
|
|
||||||
const [props, rest] = splitProps(oprops, ["onInput", "onFocus", "class"]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<textarea
|
|
||||||
onInput={(event) =>
|
|
||||||
onTextareaRefreshHeight<typeof event>(props.onInput, event)
|
|
||||||
}
|
|
||||||
onFocus={[onTextareaRefreshHeight, props.onFocus]}
|
|
||||||
class={`SizedTextarea ${props.class || ""}`}
|
|
||||||
{...rest}
|
|
||||||
></textarea>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SizedTextarea;
|
|
|
@ -33,6 +33,7 @@ const TimelinePanel: Component<{
|
||||||
() => props.client.v1.timelines[props.name],
|
() => props.client.v1.timelines[props.name],
|
||||||
() => ({ limit: 20 }),
|
() => ({ limit: 20 }),
|
||||||
);
|
);
|
||||||
|
const [typing, setTyping] = createSignal(false);
|
||||||
|
|
||||||
const tlEndObserver = new IntersectionObserver(() => {
|
const tlEndObserver = new IntersectionObserver(() => {
|
||||||
if (untrack(() => props.prefetch) && !snapshot.loading)
|
if (untrack(() => props.prefetch) && !snapshot.loading)
|
||||||
|
@ -64,6 +65,8 @@ const TimelinePanel: Component<{
|
||||||
style={{
|
style={{
|
||||||
"--scaffold-topbar-height": "0px",
|
"--scaffold-topbar-height": "0px",
|
||||||
}}
|
}}
|
||||||
|
isTyping={typing()}
|
||||||
|
onTypingChange={setTyping}
|
||||||
client={props.client}
|
client={props.client}
|
||||||
onSent={() => refetchTimeline("prev")}
|
onSent={() => refetchTimeline("prev")}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -46,6 +46,7 @@ const TootBottomSheet: Component = (props) => {
|
||||||
}>();
|
}>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const time = createTimeSource();
|
const time = createTimeSource();
|
||||||
|
const [isInTyping, setInTyping] = createSignal(false);
|
||||||
const acctText = () => decodeURIComponent(params.acct);
|
const acctText = () => decodeURIComponent(params.acct);
|
||||||
const session = useSessionForAcctStr(acctText);
|
const session = useSessionForAcctStr(acctText);
|
||||||
|
|
||||||
|
@ -69,6 +70,12 @@ const TootBottomSheet: Component = (props) => {
|
||||||
return tootId;
|
return tootId;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (location.state?.tootReply) {
|
||||||
|
setInTyping(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const [tootContextErrorUncaught, { refetch: refetchContext }] =
|
const [tootContextErrorUncaught, { refetch: refetchContext }] =
|
||||||
createResource(
|
createResource(
|
||||||
() => [session().client, params.id] as const,
|
() => [session().client, params.id] as const,
|
||||||
|
@ -275,6 +282,8 @@ const TootBottomSheet: Component = (props) => {
|
||||||
|
|
||||||
<Show when={session()!.account}>
|
<Show when={session()!.account}>
|
||||||
<TootComposer
|
<TootComposer
|
||||||
|
isTyping={isInTyping()}
|
||||||
|
onTypingChange={setInTyping}
|
||||||
mentions={defaultMentions()}
|
mentions={defaultMentions()}
|
||||||
profile={session().account!}
|
profile={session().account!}
|
||||||
replyToDisplayName={toot()?.account?.displayName || ""}
|
replyToDisplayName={toot()?.account?.displayName || ""}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
.TootComposer {
|
|
||||||
--card-gut: 8px;
|
|
||||||
contain: content;
|
|
||||||
|
|
||||||
> .MuiToolbar-root {
|
|
||||||
justify-content: space-between;
|
|
||||||
|
|
||||||
> :first-child {
|
|
||||||
margin-left: -0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
> :last-child {
|
|
||||||
margin-right: -0.5em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.reply-input {
|
|
||||||
display: flex;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.options {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: 16px;
|
|
||||||
flex-flow: row wrap;
|
|
||||||
padding-top: 16px;
|
|
||||||
padding-bottom: 8px;
|
|
||||||
margin-left: -0.5em;
|
|
||||||
margin-right: -0.5em;
|
|
||||||
|
|
||||||
animation: TootComposerFadeIn 110ms var(--tutu-anim-curve-sharp) both;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes TootComposerFadeIn {
|
|
||||||
0% {
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
100% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
11
src/timelines/TootComposer.module.css
Normal file
11
src/timelines/TootComposer.module.css
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
.composer {
|
||||||
|
composes: card from "../material/cards.module.css";
|
||||||
|
--card-gut: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.replyInput {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
|
@ -1,12 +1,10 @@
|
||||||
import {
|
import {
|
||||||
createEffect,
|
createEffect,
|
||||||
createMemo,
|
createMemo,
|
||||||
createRenderEffect,
|
|
||||||
createSignal,
|
createSignal,
|
||||||
createUniqueId,
|
createUniqueId,
|
||||||
onMount,
|
onMount,
|
||||||
Show,
|
Show,
|
||||||
type Accessor,
|
|
||||||
type Component,
|
type Component,
|
||||||
type JSX,
|
type JSX,
|
||||||
type Ref,
|
type Ref,
|
||||||
|
@ -25,9 +23,6 @@ import {
|
||||||
Switch,
|
Switch,
|
||||||
Divider,
|
Divider,
|
||||||
CircularProgress,
|
CircularProgress,
|
||||||
Toolbar,
|
|
||||||
MenuItem,
|
|
||||||
ListItemAvatar,
|
|
||||||
} from "@suid/material";
|
} from "@suid/material";
|
||||||
import {
|
import {
|
||||||
ArrowDropDown,
|
ArrowDropDown,
|
||||||
|
@ -38,11 +33,9 @@ import {
|
||||||
ListAlt as ListAltIcon,
|
ListAlt as ListAltIcon,
|
||||||
Visibility,
|
Visibility,
|
||||||
Translate,
|
Translate,
|
||||||
Close,
|
|
||||||
MoreVert,
|
|
||||||
} from "@suid/icons-material";
|
} from "@suid/icons-material";
|
||||||
import type { Account } from "../accounts/stores";
|
import type { Account } from "../accounts/stores";
|
||||||
import "./TootComposer.css";
|
import tootComposers from "./TootComposer.module.css";
|
||||||
import { makeEventListener } from "@solid-primitives/event-listener";
|
import { makeEventListener } from "@solid-primitives/event-listener";
|
||||||
import BottomSheet from "../material/BottomSheet";
|
import BottomSheet from "../material/BottomSheet";
|
||||||
import { useLanguage } from "../platform/i18n";
|
import { useLanguage } from "../platform/i18n";
|
||||||
|
@ -50,11 +43,6 @@ import iso639_1 from "iso-639-1";
|
||||||
import ChooseTootLang from "./ChooseTootLang";
|
import ChooseTootLang from "./ChooseTootLang";
|
||||||
import type { mastodon } from "masto";
|
import type { mastodon } from "masto";
|
||||||
import cardStyles from "../material/cards.module.css";
|
import cardStyles from "../material/cards.module.css";
|
||||||
import { Title } from "../material/typography";
|
|
||||||
import Menu, { createManagedMenuState } from "../material/Menu";
|
|
||||||
import { useDefaultSession } from "../masto/clients";
|
|
||||||
import { resolveCustomEmoji } from "../masto/toot";
|
|
||||||
import SizedTextarea from "../platform/SizedTextarea";
|
|
||||||
|
|
||||||
type TootVisibility = "public" | "unlisted" | "private" | "direct";
|
type TootVisibility = "public" | "unlisted" | "private" | "direct";
|
||||||
|
|
||||||
|
@ -208,10 +196,6 @@ function randomChoose<T extends any[]>(
|
||||||
return K[idx];
|
return K[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
function useRandomChoice<T>(choices: () => T[]): Accessor<T> {
|
|
||||||
return createMemo(() => randomChoose(Math.random(), choices()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function cancelEvent(event: Event) {
|
function cancelEvent(event: Event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
@ -222,27 +206,27 @@ const TootComposer: Component<{
|
||||||
profile?: Account;
|
profile?: Account;
|
||||||
replyToDisplayName?: string;
|
replyToDisplayName?: string;
|
||||||
mentions?: readonly string[];
|
mentions?: readonly string[];
|
||||||
|
isTyping?: boolean;
|
||||||
|
onTypingChange: (value: boolean) => void;
|
||||||
client?: mastodon.rest.Client;
|
client?: mastodon.rest.Client;
|
||||||
inReplyToId?: string;
|
inReplyToId?: string;
|
||||||
onSent?: (status: mastodon.v1.Status) => void;
|
onSent?: (status: mastodon.v1.Status) => void;
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
let inputRef: HTMLTextAreaElement;
|
let inputRef: HTMLTextAreaElement;
|
||||||
|
let sendKey: string | undefined;
|
||||||
|
|
||||||
const session = useDefaultSession();
|
const typing = () => props.isTyping;
|
||||||
|
const setTyping = (v: boolean) => props.onTypingChange(v);
|
||||||
const [active, setActive] = createSignal(false);
|
|
||||||
const [sending, setSending] = createSignal(false);
|
const [sending, setSending] = createSignal(false);
|
||||||
const [visibility, setVisibility] = createSignal<TootVisibility>("public");
|
const [visibility, setVisibility] = createSignal<TootVisibility>("public");
|
||||||
const [permPicker, setPermPicker] = createSignal(false);
|
const [permPicker, setPermPicker] = createSignal(false);
|
||||||
const [language, setLanguage] = createSignal("en");
|
const [language, setLanguage] = createSignal("en");
|
||||||
const [langPickerOpen, setLangPickerOpen] = createSignal(false);
|
const [langPickerOpen, setLangPickerOpen] = createSignal(false);
|
||||||
const appLanguage = useLanguage();
|
const appLanguage = useLanguage();
|
||||||
const [openMenu, menuState] = createManagedMenuState();
|
|
||||||
|
|
||||||
const randomPlaceholder = useRandomChoice(() => [
|
const randomPlaceholder = createMemo(() =>
|
||||||
"What's happening?",
|
randomChoose(Math.random(), ["What's happening?", "What do your think?"]),
|
||||||
"What do you think?",
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const lang = appLanguage().split("-")[0];
|
const lang = appLanguage().split("-")[0];
|
||||||
|
@ -250,11 +234,15 @@ const TootComposer: Component<{
|
||||||
});
|
});
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (active()) {
|
if (typing()) {
|
||||||
setTimeout(() => inputRef.focus(), 0);
|
setTimeout(() => inputRef.focus(), 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
makeEventListener(inputRef, "focus", () => setTyping(true));
|
||||||
|
});
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (inputRef.value !== "") return;
|
if (inputRef.value !== "") return;
|
||||||
if (props.mentions) {
|
if (props.mentions) {
|
||||||
|
@ -264,7 +252,7 @@ const TootComposer: Component<{
|
||||||
});
|
});
|
||||||
|
|
||||||
const containerStyle = () =>
|
const containerStyle = () =>
|
||||||
active() || permPicker()
|
typing() || permPicker()
|
||||||
? {
|
? {
|
||||||
position: "sticky" as const,
|
position: "sticky" as const,
|
||||||
top: "var(--scaffold-topbar-height, 0)",
|
top: "var(--scaffold-topbar-height, 0)",
|
||||||
|
@ -287,15 +275,17 @@ const TootComposer: Component<{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const idempotencyKey = createMemo(() => window.crypto.randomUUID());
|
const getOrGenSendKey = () => {
|
||||||
|
if (sendKey === undefined) {
|
||||||
|
sendKey = window.crypto.randomUUID();
|
||||||
|
}
|
||||||
|
return sendKey;
|
||||||
|
};
|
||||||
|
|
||||||
const send = async () => {
|
const send = async () => {
|
||||||
const client = session()?.client;
|
|
||||||
if (!client) return;
|
|
||||||
|
|
||||||
setSending(true);
|
setSending(true);
|
||||||
try {
|
try {
|
||||||
const status = await client.v1.statuses.create(
|
const status = await props.client!.v1.statuses.create(
|
||||||
{
|
{
|
||||||
status: inputRef.value,
|
status: inputRef.value,
|
||||||
language: language(),
|
language: language(),
|
||||||
|
@ -305,7 +295,7 @@ const TootComposer: Component<{
|
||||||
{
|
{
|
||||||
requestInit: {
|
requestInit: {
|
||||||
headers: {
|
headers: {
|
||||||
["Idempotency-Key"]: idempotencyKey(),
|
["Idempotency-Key"]: getOrGenSendKey(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -321,8 +311,11 @@ const TootComposer: Component<{
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={props.ref}
|
ref={props.ref}
|
||||||
class={/* @once */ `TootComposer ${cardStyles.card}`}
|
class={tootComposers.composer}
|
||||||
style={containerStyle()}
|
style={containerStyle()}
|
||||||
|
onClick={() => {
|
||||||
|
inputRef.focus();
|
||||||
|
}}
|
||||||
on:touchend={
|
on:touchend={
|
||||||
cancelEvent
|
cancelEvent
|
||||||
/* on: is required to register the event handler on the exact element */
|
/* on: is required to register the event handler on the exact element */
|
||||||
|
@ -330,63 +323,23 @@ const TootComposer: Component<{
|
||||||
on:touchmove={cancelEvent}
|
on:touchmove={cancelEvent}
|
||||||
on:wheel={cancelEvent}
|
on:wheel={cancelEvent}
|
||||||
>
|
>
|
||||||
<Show when={active()}>
|
<div class={tootComposers.replyInput}>
|
||||||
<Toolbar class={cardStyles.cardNoPad}>
|
|
||||||
<IconButton
|
|
||||||
onClick={[setActive, false]}
|
|
||||||
aria-label="Close the composer"
|
|
||||||
>
|
|
||||||
<Close />
|
|
||||||
</IconButton>
|
|
||||||
<IconButton
|
|
||||||
onClick={(e) => openMenu(e.currentTarget.getBoundingClientRect())}
|
|
||||||
>
|
|
||||||
<MoreVert />
|
|
||||||
</IconButton>
|
|
||||||
</Toolbar>
|
|
||||||
<div class={cardStyles.cardNoPad}>
|
|
||||||
<Menu {...menuState}>
|
|
||||||
<MenuItem>
|
|
||||||
<ListItemAvatar>
|
|
||||||
<Avatar src={session()?.account.inf?.avatar}></Avatar>
|
|
||||||
</ListItemAvatar>
|
|
||||||
<ListItemText secondary={"Default account"}>
|
|
||||||
<span
|
|
||||||
ref={(e) => {
|
|
||||||
createRenderEffect(() => {
|
|
||||||
const inf = session()?.account.inf;
|
|
||||||
return (e.innerHTML = resolveCustomEmoji(
|
|
||||||
inf?.displayName || "",
|
|
||||||
inf?.emojis ?? [],
|
|
||||||
));
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
></span>
|
|
||||||
</ListItemText>
|
|
||||||
</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
|
|
||||||
<div class="reply-input">
|
|
||||||
<Show when={props.profile}>
|
<Show when={props.profile}>
|
||||||
<Avatar
|
<Avatar
|
||||||
src={props.profile!.inf?.avatar}
|
src={props.profile!.inf?.avatar}
|
||||||
sx={{ marginLeft: "-0.25em" }}
|
sx={{ marginLeft: "-0.25em" }}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
<SizedTextarea
|
<textarea
|
||||||
ref={inputRef!}
|
ref={inputRef!}
|
||||||
placeholder={
|
placeholder={
|
||||||
props.replyToDisplayName
|
props.replyToDisplayName
|
||||||
? `Reply to ${props.replyToDisplayName}...`
|
? `Reply to ${props.replyToDisplayName}...`
|
||||||
: randomPlaceholder()
|
: randomPlaceholder()
|
||||||
}
|
}
|
||||||
onFocus={[setActive, true]}
|
|
||||||
style={{ width: "100%", border: "none" }}
|
style={{ width: "100%", border: "none" }}
|
||||||
disabled={sending()}
|
disabled={sending()}
|
||||||
autocomplete="off"
|
></textarea>
|
||||||
></SizedTextarea>
|
|
||||||
<Show when={props.client}>
|
<Show when={props.client}>
|
||||||
<Show
|
<Show
|
||||||
when={!sending()}
|
when={!sending()}
|
||||||
|
@ -402,38 +355,32 @@ const TootComposer: Component<{
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<IconButton
|
<IconButton sx={{ marginRight: "-0.5em" }} onClick={send}>
|
||||||
sx={{ marginRight: "-0.5em" }}
|
|
||||||
onClick={send}
|
|
||||||
aria-label="Send"
|
|
||||||
>
|
|
||||||
<Send />
|
<Send />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Show>
|
</Show>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Show when={active()}>
|
<Show when={typing()}>
|
||||||
<div class="options">
|
<div
|
||||||
<Button
|
style={{
|
||||||
startIcon={<Translate />}
|
display: "flex",
|
||||||
endIcon={<ArrowDropDown />}
|
"justify-content": "flex-end",
|
||||||
onClick={[setLangPickerOpen, true]}
|
"margin-top": "8px",
|
||||||
disabled={sending()}
|
gap: "16px",
|
||||||
>
|
"flex-flow": "row wrap",
|
||||||
<span style={{ "vertical-align": "bottom" }}>
|
}}
|
||||||
{iso639_1.getNativeName(language())}
|
>
|
||||||
</span>
|
<Button onClick={[setLangPickerOpen, true]} disabled={sending()}>
|
||||||
|
<Translate sx={{ marginTop: "-0.25em", marginRight: "0.25em" }} />
|
||||||
|
{iso639_1.getNativeName(language())}
|
||||||
|
<ArrowDropDown sx={{ marginTop: "-0.25em" }} />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button onClick={[setPermPicker, true]} disabled={sending()}>
|
||||||
startIcon={<Visibility />}
|
<Visibility sx={{ marginTop: "-0.15em", marginRight: "0.25em" }} />
|
||||||
endIcon={<ArrowDropDown />}
|
{visibilityText()}
|
||||||
onClick={[setPermPicker, true]}
|
<ArrowDropDown sx={{ marginTop: "-0.25em" }} />
|
||||||
disabled={sending()}
|
|
||||||
>
|
|
||||||
<span style={{ "vertical-align": "bottom" }}>
|
|
||||||
{visibilityText()}
|
|
||||||
</span>
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue