diff --git a/public/assets/social/bilibili.svg b/public/assets/social/bilibili.svg new file mode 100644 index 00000000..188db4d4 --- /dev/null +++ b/public/assets/social/bilibili.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/github.svg b/public/assets/social/github.svg new file mode 100644 index 00000000..a8d11740 --- /dev/null +++ b/public/assets/social/github.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/assets/social/jike.png b/public/assets/social/jike.png new file mode 100644 index 00000000..0d669431 Binary files /dev/null and b/public/assets/social/jike.png differ diff --git a/public/assets/social/jike.svg b/public/assets/social/jike.svg new file mode 100644 index 00000000..6a032473 --- /dev/null +++ b/public/assets/social/jike.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/medium.svg b/public/assets/social/medium.svg new file mode 100644 index 00000000..b2666bf3 --- /dev/null +++ b/public/assets/social/medium.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/nintendo_switch.svg b/public/assets/social/nintendo_switch.svg new file mode 100644 index 00000000..a0aa719e --- /dev/null +++ b/public/assets/social/nintendo_switch.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/pixiv.ico b/public/assets/social/pixiv.ico new file mode 100644 index 00000000..fbb298cd Binary files /dev/null and b/public/assets/social/pixiv.ico differ diff --git a/public/assets/social/pixiv.svg b/public/assets/social/pixiv.svg new file mode 100644 index 00000000..6c89b590 --- /dev/null +++ b/public/assets/social/pixiv.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/playstation.svg b/public/assets/social/playstation.svg new file mode 100644 index 00000000..e34340d8 --- /dev/null +++ b/public/assets/social/playstation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/assets/social/substack.svg b/public/assets/social/substack.svg new file mode 100644 index 00000000..f4707f6a --- /dev/null +++ b/public/assets/social/substack.svg @@ -0,0 +1,4 @@ + + + + diff --git a/public/assets/social/telegram.svg b/public/assets/social/telegram.svg new file mode 100644 index 00000000..fbccaada --- /dev/null +++ b/public/assets/social/telegram.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/assets/social/twitter.svg b/public/assets/social/twitter.svg new file mode 100644 index 00000000..6d4e417d --- /dev/null +++ b/public/assets/social/twitter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/dashboard/SettingsLayout.tsx b/src/components/dashboard/SettingsLayout.tsx index 470c20d3..bd5f5059 100644 --- a/src/components/dashboard/SettingsLayout.tsx +++ b/src/components/dashboard/SettingsLayout.tsx @@ -16,6 +16,10 @@ export const SettingsLayout: React.FC<{ type === "site" ? [ { text: "General", href: `/dashboard/${subdomain}/settings/general` }, + { + text: "Social Platforms", + href: `/dashboard/${subdomain}/settings/social-platforms`, + }, { text: "Navigation", href: `/dashboard/${subdomain}/settings/navigation`, diff --git a/src/components/icons/PlanetIcon.tsx b/src/components/icons/PlanetIcon.tsx new file mode 100644 index 00000000..e8b41ad0 --- /dev/null +++ b/src/components/icons/PlanetIcon.tsx @@ -0,0 +1,20 @@ +import React from "react" + +export const PlanetIcon: React.FC> = ( + props, +) => { + return ( + + + + ) +} diff --git a/src/components/site/Platform.tsx b/src/components/site/Platform.tsx new file mode 100644 index 00000000..da86f056 --- /dev/null +++ b/src/components/site/Platform.tsx @@ -0,0 +1,106 @@ +import { Image } from "~/components/ui/Image" +import { UniLink } from "~/components/ui/UniLink" +import { PlanetIcon } from "~/components/icons/PlanetIcon" +import { Tooltip } from "~/components/ui/Tooltip" +import clsx from "clsx" + +const syncMap: { + [key: string]: { + name: string + icon: string + url?: string + } +} = { + telegram: { + name: "Telegram", + icon: "/assets/social/telegram.svg", + url: "https://t.me/{username}", + }, + tg_channel: { + name: "Telegram Channel", + icon: "/assets/social/telegram.svg", + url: "https://t.me/{username}", + }, + twitter: { + name: "Twitter", + icon: "/assets/social/twitter.svg", + url: "https://twitter.com/{username}", + }, + twitter_id: { + name: "Twitter", + icon: "/assets/social/twitter.svg", + url: "https://twitter.com/i/user/{username}", + }, + pixiv: { + name: "Pixiv", + icon: "/assets/social/pixiv.ico", + url: "https://www.pixiv.net/users/{username}", + }, + substack: { + name: "Substack", + icon: "/assets/social/substack.svg", + url: "https://{username}.substack.com/", + }, + medium: { + name: "Mediam", + icon: "/assets/social/medium.svg", + url: "https://medium.com/@{username}", + }, + github: { + name: "GitHub", + icon: "/assets/social/github.svg", + url: "https://github.com/{username}", + }, + jike: { + name: "Jike", + icon: "/assets/social/jike.png", + url: "https://web.okjike.com/u/{username}", + }, + bilibili: { + name: "bilibili", + icon: "/assets/social/bilibili.svg", + url: "https://space.bilibili.com/{username}", + }, + playstation: { + name: "PlayStation", + icon: "/assets/social/playstation.svg", + url: "https://psnprofiles.com/{username}", + }, + "nintendo switch": { + name: "Nintendo Switch", + icon: "/assets/social/nintendo_switch.svg", + }, +} + +export const Platform: React.FC<{ + platform: string + username: string + className?: string +}> = ({ platform, username, className }) => { + platform = platform.toLowerCase() + return ( + + + + {syncMap[platform]?.icon ? ( + {platform} + ) : ( + + + + )} + + + + ) +} diff --git a/src/components/site/SiteFooter.tsx b/src/components/site/SiteFooter.tsx index f7c3ca89..1a7c703b 100644 --- a/src/components/site/SiteFooter.tsx +++ b/src/components/site/SiteFooter.tsx @@ -3,6 +3,7 @@ import { UniLink } from "../ui/UniLink" import { Profile, Note } from "~/lib/types" import Script from "next/script" import Image from "next/image" +import { Platform } from "~/components/site/Platform" export const SiteFooter: React.FC<{ site?: Profile | null @@ -11,11 +12,11 @@ export const SiteFooter: React.FC<{ return ( <> {site?.ga && ( diff --git a/src/components/ui/Tooltip.tsx b/src/components/ui/Tooltip.tsx index 1891743f..c36fa9f8 100644 --- a/src/components/ui/Tooltip.tsx +++ b/src/components/ui/Tooltip.tsx @@ -13,14 +13,21 @@ import { useDismiss, useTransitionStyles, } from "@floating-ui/react" +import clsx from "clsx" interface Props { label: string placement?: Placement children: JSX.Element + className?: string } -export const Tooltip = ({ children, label, placement = "top" }: Props) => { +export const Tooltip = ({ + children, + label, + placement = "top", + className, +}: Props) => { const [open, setOpen] = useState(false) const { x, y, refs, strategy, context } = useFloating({ @@ -54,7 +61,10 @@ export const Tooltip = ({ children, label, placement = "top" }: Props) => { {isMounted && (
["connected_accounts"][number] & { + id: string +} + +type UpdateItem = (id: string, newItem: Partial) => void + +type RemoveItem = (id: string) => void + +const SortableNavigationItem: React.FC<{ + item: Item + updateItem: UpdateItem + removeItem: RemoveItem +}> = ({ item, updateItem, removeItem }) => { + return ( +
+
+ +
+ ) => + updateItem(item.id, { platform: e.target.value }) + } + /> + ) => + updateItem(item.id, { identity: e.target.value }) + } + /> +
+ +
+
+ +
+
+ ) +} + +export default function SiteSettingsNavigationPage() { + const router = useRouter() + + const subdomain = router.query.subdomain as string + + const updateSite = useUpdateSite() + const site = useGetSite(subdomain) + + const [items, setItems] = useState([]) + + const itemsModified = useMemo(() => { + if (!site.isSuccess) return false + return !equal(items, site.data?.connected_accounts) + }, [items, site.data, site.isSuccess]) + + const updateItem: UpdateItem = (id, newItem) => { + setItems((items) => { + return items.map((item) => { + if (item.id === id) { + return { ...item, ...newItem } + } + return item + }) + }) + } + + const newEmptyItem = () => { + setItems((items) => [ + ...items, + { id: nanoid(), platform: "", identity: "" }, + ]) + } + + const handleSubmit = (e: FormEvent) => { + e.preventDefault() + updateSite.mutate({ + site: site.data?.username!, + connected_accounts: items.map(({ id, ...item }) => item), + }) + } + + useEffect(() => { + if (updateSite.isSuccess) { + if (updateSite.data?.code === 0) { + toast.success("Saved") + } else { + toast.error("Failed to save" + ": " + updateSite.data.message) + } + } else if (updateSite.isError) { + toast.error("Failed to save") + } + }, [updateSite.isSuccess, updateSite.isError]) + + const removeItem: RemoveItem = (id) => { + setItems((items) => items.filter((item) => item.id !== id)) + } + + const [hasSet, setHasSet] = useState(false) + useEffect(() => { + if (site.data?.connected_accounts && !hasSet) { + setHasSet(true) + setItems( + site.data?.connected_accounts.map((item) => ({ + id: nanoid(), + ...item, + })), + ) + } + }, [site.data?.connected_accounts, hasSet]) + + return ( + +
+

Tips:

+

+ + These social platforms will be displayed in the bottom right hand + corner of your xLog. + +

+

+ + You can also connect to Twitter, Telegram Channel, Medium, Substack + and more and automatically sync content on{" "} + + xSync + + . When you have set up the sync there, it will also show here. + +

+
+
+
+ {items.length === 0 && ( +
+ No navigation items yet +
+ )} + + {items.map((item) => { + return ( + + ) + })} + + +
+
+ + +
+
+
+ ) +} + +SiteSettingsNavigationPage.getLayout = (page: ReactElement) => { + return {page} +}