Compare commits
2 commits
4075c41942
...
a924c80bbe
Author | SHA1 | Date | |
---|---|---|---|
|
a924c80bbe | ||
|
8834c4d3ae |
2 changed files with 203 additions and 68 deletions
|
@ -14,29 +14,41 @@ type Props = {
|
|||
anchor: () => DOMRect;
|
||||
};
|
||||
|
||||
function adjustMenuPosition(
|
||||
rect: DOMRect,
|
||||
[left, top]: [number, number],
|
||||
{ width, height }: { width: number; height: number },
|
||||
) {
|
||||
const ntop = rect.bottom > height ? top - (rect.bottom - height) : top;
|
||||
const nleft = rect.right > width ? left - (rect.right - width) : left;
|
||||
return [nleft, ntop] as [number, number];
|
||||
function px(n?: number) {
|
||||
if (n) {
|
||||
return `${n}px`;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const Menu: ParentComponent<Props> = (props) => {
|
||||
let root: HTMLDialogElement;
|
||||
const [pos, setPos] = createSignal<[number, number]>([0, 0]);
|
||||
const windowSize = useWindowSize();
|
||||
|
||||
const [anchorPos, setAnchorPos] = createSignal<{
|
||||
left?: number;
|
||||
top?: number;
|
||||
}>({});
|
||||
|
||||
let openAnimationOrigin: "lt" | "rt" = "lt";
|
||||
|
||||
createEffect(() => {
|
||||
if (props.open) {
|
||||
const a = props.anchor();
|
||||
|
||||
if (!root.open) {
|
||||
root.showModal();
|
||||
const rend = root.getBoundingClientRect();
|
||||
|
||||
setPos(adjustMenuPosition(rend, [a.left, a.top], windowSize));
|
||||
const { width } = windowSize;
|
||||
const { left, top, right } = a;
|
||||
if (left > width / 2) {
|
||||
openAnimationOrigin = "rt";
|
||||
setAnchorPos({
|
||||
left: right - rend.width,
|
||||
top,
|
||||
});
|
||||
|
||||
const overflow = root.style.overflow;
|
||||
root.style.overflow = "hidden";
|
||||
|
@ -45,7 +57,6 @@ const Menu: ParentComponent<Props> = (props) => {
|
|||
const animation = root.animate(
|
||||
{
|
||||
height: [`${rend.height / 2}px`, `${rend.height}px`],
|
||||
width: [`${rend.width / 4 * 3}px`, `${rend.width}px`],
|
||||
},
|
||||
{
|
||||
duration,
|
||||
|
@ -57,13 +68,30 @@ const Menu: ParentComponent<Props> = (props) => {
|
|||
() => (root.style.overflow = overflow),
|
||||
);
|
||||
} else {
|
||||
setPos(
|
||||
adjustMenuPosition(
|
||||
root.getBoundingClientRect(),
|
||||
[a.left, a.top],
|
||||
windowSize,
|
||||
),
|
||||
openAnimationOrigin = "lt";
|
||||
setAnchorPos({ left, top });
|
||||
|
||||
const overflow = root.style.overflow;
|
||||
root.style.overflow = "hidden";
|
||||
const duration = (rend.height / 1600) * 1000;
|
||||
const easing = ANIM_CURVE_STD;
|
||||
const animation = root.animate(
|
||||
{
|
||||
height: [`${rend.height / 2}px`, `${rend.height}px`],
|
||||
width: [`${(rend.width / 4) * 3}px`, `${rend.width}px`],
|
||||
},
|
||||
{
|
||||
duration,
|
||||
easing,
|
||||
},
|
||||
);
|
||||
animation.addEventListener(
|
||||
"finish",
|
||||
() => (root.style.overflow = overflow),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// TODO: update the pos
|
||||
}
|
||||
} else {
|
||||
animateClose();
|
||||
|
@ -72,12 +100,13 @@ const Menu: ParentComponent<Props> = (props) => {
|
|||
|
||||
const animateClose = () => {
|
||||
const rend = root.getBoundingClientRect();
|
||||
if (openAnimationOrigin === "lt") {
|
||||
const overflow = root.style.overflow;
|
||||
root.style.overflow = "hidden";
|
||||
const animation = root.animate(
|
||||
{
|
||||
height: [`${rend.height}px`, `${rend.height / 2}px`],
|
||||
width: [`${rend.width}px`, `${rend.width / 4 * 3}px`],
|
||||
width: [`${rend.width}px`, `${(rend.width / 4) * 3}px`],
|
||||
},
|
||||
{
|
||||
duration: (rend.height / 2 / 1600) * 1000,
|
||||
|
@ -88,6 +117,23 @@ const Menu: ParentComponent<Props> = (props) => {
|
|||
root.style.overflow = overflow;
|
||||
root.close();
|
||||
});
|
||||
} else {
|
||||
const overflow = root.style.overflow;
|
||||
root.style.overflow = "hidden";
|
||||
const animation = root.animate(
|
||||
{
|
||||
height: [`${rend.height}px`, `${rend.height / 2}px`],
|
||||
},
|
||||
{
|
||||
duration: (rend.height / 2 / 1600) * 1000,
|
||||
easing: ANIM_CURVE_STD,
|
||||
},
|
||||
);
|
||||
animation.addEventListener("finish", () => {
|
||||
root.style.overflow = overflow;
|
||||
root.close();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -111,14 +157,15 @@ const Menu: ParentComponent<Props> = (props) => {
|
|||
}
|
||||
}}
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: `${pos()[0]}px`,
|
||||
top: `${pos()[1]}px`,
|
||||
position: "fixed",
|
||||
left: px(anchorPos().left),
|
||||
top: px(anchorPos().top),
|
||||
border: "none",
|
||||
"border-radius": "2px",
|
||||
padding: 0,
|
||||
"max-width": "560px",
|
||||
width: "max-content",
|
||||
/*"min-width": "20vw", */
|
||||
/* FIXME: the content may be overflow */
|
||||
"box-shadow": "var(--tutu-shadow-e8)",
|
||||
}}
|
||||
>
|
||||
|
|
|
@ -2,14 +2,34 @@ import {
|
|||
createRenderEffect,
|
||||
createResource,
|
||||
createSignal,
|
||||
createUniqueId,
|
||||
For,
|
||||
onCleanup,
|
||||
Show,
|
||||
type Component,
|
||||
} from "solid-js";
|
||||
import Scaffold from "../material/Scaffold";
|
||||
import { AppBar, Avatar, Button, IconButton, Toolbar } from "@suid/material";
|
||||
import { Close, MoreVert, Verified } from "@suid/icons-material";
|
||||
import {
|
||||
AppBar,
|
||||
Avatar,
|
||||
Button,
|
||||
Divider,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
MenuItem,
|
||||
Toolbar,
|
||||
} from "@suid/material";
|
||||
import {
|
||||
Close,
|
||||
Edit,
|
||||
ExpandMore,
|
||||
MoreVert,
|
||||
OpenInBrowser,
|
||||
Send,
|
||||
Share,
|
||||
Verified,
|
||||
} from "@suid/icons-material";
|
||||
import { Title } from "../material/typography";
|
||||
import { useNavigate, useParams } from "@solidjs/router";
|
||||
import { useSessionForAcctStr } from "../masto/clients";
|
||||
|
@ -21,6 +41,8 @@ import { createTimeline } from "../masto/timelines";
|
|||
import TootList from "../timelines/TootList";
|
||||
import { createTimeSource, TimeSourceProvider } from "../platform/timesrc";
|
||||
import TootFilterButton from "./TootFilterButton";
|
||||
import Menu from "../material/Menu";
|
||||
import { share } from "../platform/share";
|
||||
|
||||
const Profile: Component = () => {
|
||||
const navigate = useNavigate();
|
||||
|
@ -34,6 +56,10 @@ const Profile: Component = () => {
|
|||
const windowSize = useWindowSize();
|
||||
const time = createTimeSource();
|
||||
|
||||
const menuButId = createUniqueId();
|
||||
|
||||
const [menuOpen, setMenuOpen] = createSignal(false);
|
||||
|
||||
const [scrolledPastBanner, setScrolledPastBanner] = createSignal(false);
|
||||
const obx = new IntersectionObserver(
|
||||
(entries) => {
|
||||
|
@ -58,12 +84,13 @@ const Profile: Component = () => {
|
|||
);
|
||||
|
||||
const [recentTootFilter, setRecentTootFilter] = createSignal({
|
||||
boost: true,
|
||||
boost: false,
|
||||
reply: true,
|
||||
original: true,
|
||||
});
|
||||
|
||||
const [recentToots] = createTimeline(
|
||||
const [recentToots, recentTootChunk, { refetch: refetchRecentToots }] =
|
||||
createTimeline(
|
||||
() => session().client.v1.accounts.$select(params.id).statuses,
|
||||
() => {
|
||||
const { boost, reply } = recentTootFilter();
|
||||
|
@ -140,7 +167,11 @@ const Profile: Component = () => {
|
|||
paddingTop: "var(--safe-area-inset-top)",
|
||||
}}
|
||||
>
|
||||
<IconButton color="inherit" onClick={[navigate, -1]}>
|
||||
<IconButton
|
||||
color="inherit"
|
||||
onClick={[navigate, -1]}
|
||||
aria-label="Close"
|
||||
>
|
||||
<Close />
|
||||
</IconButton>
|
||||
<Title
|
||||
|
@ -153,13 +184,52 @@ const Profile: Component = () => {
|
|||
createRenderEffect(() => (e.innerHTML = displayName()))
|
||||
}
|
||||
></Title>
|
||||
<IconButton color="inherit">
|
||||
|
||||
<IconButton
|
||||
id={menuButId}
|
||||
color="inherit"
|
||||
onClick={[setMenuOpen, true]}
|
||||
>
|
||||
<MoreVert />
|
||||
</IconButton>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
}
|
||||
>
|
||||
<Menu
|
||||
open={menuOpen()}
|
||||
onClose={[setMenuOpen, false]}
|
||||
anchor={() =>
|
||||
document.getElementById(menuButId)!.getBoundingClientRect()
|
||||
}
|
||||
>
|
||||
<MenuItem disabled>
|
||||
<ListItemIcon>
|
||||
<Edit />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Edit...</ListItemText>
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem disabled>
|
||||
<ListItemIcon>
|
||||
<Send />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Mention {profile()?.displayName || ""}...</ListItemText>
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem component={"a"} href={profile()?.url} target="_blank" rel="noopener noreferrer">
|
||||
<ListItemIcon>
|
||||
<OpenInBrowser />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Open in browser...</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => share({ url: profile()?.url })}>
|
||||
<ListItemIcon>
|
||||
<Share />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Share...</ListItemText>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<div
|
||||
style={{
|
||||
width: "100%",
|
||||
|
@ -251,7 +321,7 @@ const Profile: Component = () => {
|
|||
<div>
|
||||
<TootFilterButton
|
||||
options={{
|
||||
boost: "Boosteds",
|
||||
boost: "Boosts",
|
||||
reply: "Replies",
|
||||
original: "Originals",
|
||||
}}
|
||||
|
@ -268,6 +338,24 @@ const Profile: Component = () => {
|
|||
onChangeToot={recentToots.set}
|
||||
/>
|
||||
</TimeSourceProvider>
|
||||
|
||||
<Show when={!recentTootChunk()?.done}>
|
||||
<div
|
||||
style={{
|
||||
"text-align": "center",
|
||||
"padding-bottom": "var(--safe-area-inset-bottom)",
|
||||
}}
|
||||
>
|
||||
<IconButton
|
||||
aria-label="Load More"
|
||||
size="large"
|
||||
color="primary"
|
||||
onClick={[refetchRecentToots, "prev"]}
|
||||
>
|
||||
<ExpandMore />
|
||||
</IconButton>
|
||||
</div>
|
||||
</Show>
|
||||
</Scaffold>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue