-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathFloatingComposeButton.tsx
More file actions
159 lines (153 loc) · 6.05 KB
/
FloatingComposeButton.tsx
File metadata and controls
159 lines (153 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { A } from "@solidjs/router";
import { graphql } from "relay-runtime";
import { Show } from "solid-js";
import { createFragment } from "solid-relay";
import { Button } from "~/components/ui/button.tsx";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "~/components/ui/dropdown-menu.tsx";
import { useSidebar } from "~/components/ui/sidebar.tsx";
import { useNoteCompose } from "~/contexts/NoteComposeContext.tsx";
import { useLingui } from "~/lib/i18n/macro.d.ts";
import type { FloatingComposeButton_signedAccount$key } from "./__generated__/FloatingComposeButton_signedAccount.graphql.ts";
export interface FloatingComposeButtonProps {
show: boolean;
username?: string;
$signedAccount?: FloatingComposeButton_signedAccount$key | null;
}
export function FloatingComposeButton(props: FloatingComposeButtonProps) {
const { t } = useLingui();
const { isMobile, state } = useSidebar();
const { open: openNoteCompose } = useNoteCompose();
const signedAccount = createFragment(
graphql`
fragment FloatingComposeButton_signedAccount on Account
@argumentDefinitions(
cursor: { type: "String" }
count: { type: "Int", defaultValue: 3 }
) {
articleDrafts(after: $cursor, first: $count)
@connection(key: "FloatingComposeButton_articleDrafts") {
__id
edges {
node {
id
}
}
}
}
`,
() => props.$signedAccount,
);
const shouldShow = () =>
props.show && (isMobile() || state() === "collapsed");
return (
<>
<Show when={shouldShow()}>
<div class="fixed bottom-6 right-6 z-50">
<DropdownMenu modal={false}>
<DropdownMenuTrigger>
<Button
size="lg"
class="size-14 rounded-full shadow-lg"
aria-label={t`Compose`}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 4.5v15m7.5-7.5h-15"
/>
</svg>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
onSelect={openNoteCompose}
class="cursor-pointer"
>
<div class="flex items-center gap-2 whitespace-nowrap">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-4 shrink-0"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"
/>
</svg>
<span>{t`Create Note`}</span>
</div>
</DropdownMenuItem>
<Show when={props.username}>
<DropdownMenuItem class="cursor-pointer">
<A
href={`/@${props.username}/drafts/new`}
class="flex items-center gap-2 whitespace-nowrap"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-4 shrink-0"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"
/>
</svg>
<span>{t`Create Article`}</span>
</A>
</DropdownMenuItem>
<Show
when={(signedAccount()?.articleDrafts.edges.length ?? 0) > 0}
>
<DropdownMenuItem class="cursor-pointer">
<A
href={`/@${props.username}/drafts`}
class="flex items-center gap-2 whitespace-nowrap"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-4 shrink-0"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"
/>
</svg>
<span>{t`Go to Drafts`}</span>
</A>
</DropdownMenuItem>
</Show>
</Show>
</DropdownMenuContent>
</DropdownMenu>
</div>
</Show>
</>
);
}