From 58645e1dfc0124bcd74e1c7b7ba3c62b7001258d Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 11 Feb 2023 01:27:40 +0000 Subject: [PATCH] feat: social platforms --- public/assets/social/bilibili.svg | 1 + public/assets/social/github.svg | 3 + public/assets/social/jike.png | Bin 0 -> 6220 bytes public/assets/social/jike.svg | 1 + public/assets/social/medium.svg | 1 + public/assets/social/nintendo_switch.svg | 1 + public/assets/social/pixiv.ico | Bin 0 -> 15086 bytes public/assets/social/pixiv.svg | 1 + public/assets/social/playstation.svg | 1 + public/assets/social/substack.svg | 4 + public/assets/social/telegram.svg | 13 ++ public/assets/social/twitter.svg | 1 + src/components/dashboard/SettingsLayout.tsx | 4 + src/components/icons/PlanetIcon.tsx | 20 ++ src/components/site/Platform.tsx | 106 +++++++++ src/components/site/SiteFooter.tsx | 17 +- src/components/ui/Tooltip.tsx | 14 +- src/models/site.model.ts | 4 + .../[subdomain]/settings/social-platforms.tsx | 211 ++++++++++++++++++ 19 files changed, 399 insertions(+), 4 deletions(-) create mode 100644 public/assets/social/bilibili.svg create mode 100644 public/assets/social/github.svg create mode 100644 public/assets/social/jike.png create mode 100644 public/assets/social/jike.svg create mode 100644 public/assets/social/medium.svg create mode 100644 public/assets/social/nintendo_switch.svg create mode 100644 public/assets/social/pixiv.ico create mode 100644 public/assets/social/pixiv.svg create mode 100644 public/assets/social/playstation.svg create mode 100644 public/assets/social/substack.svg create mode 100644 public/assets/social/telegram.svg create mode 100644 public/assets/social/twitter.svg create mode 100644 src/components/icons/PlanetIcon.tsx create mode 100644 src/components/site/Platform.tsx create mode 100644 src/pages/dashboard/[subdomain]/settings/social-platforms.tsx 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 0000000000000000000000000000000000000000..0d669431d4d3a561d36d979ed72da69889df6a43 GIT binary patch literal 6220 zcmV-S7_;YzP)Py221!IgRCodHT?>?5ReApRxsS{v&v}Gol1RX0MFUzuT~JmRgiyMuvTUIZO5|;c z;v$r`QWm8Zt3g(mR-vG)0zzRSk4BLittb=&6$)xFkf32fB$CWzOfoZ>%p~);kKO;@ z`|fkky)$>_oHO^Fd+t5|&brzA?6V*L`SzDT|M~ah2#83Ka!nEr@0ksKBWakGO+g}^ zgdD~kYKuV1%0ViVfg_15q|zCX;+R;rZ=|+D6?+%OWOyk#xU>z9j;w*aJPQP@29T?; z_hlgQibFjhFbE*tz;W9J!umOm+Owjo?>Ds&JT$_{{cWouCojc^Js%(R6eepehC9eU z#eNX-S&)gxV9Ci(39&UBWN)VJKnX1S7tDiE>k5$aa{PV3bjopqBOu@)YUoEHA@385 z26hDbw1E&<_H=asjNAZuxDJJ%7vuwQ+Yv`Vz!peYw~0l4F9#uMRS7J6k86e8_&?&m zzKy7HTZ0go+pJRrgm@Y?^53FH-dW8js2YJ~Py0nk+B@*KteOIHTMdMOfGh}cCnOV} z7Yh##SL4ZMOkmWy3n4pxKMM1aY6!$_!~p@(jW6?8i6#9{&-7`nnKU5xcdUVIW;?dQ zwtZP%d9yU|5kT!ay*76L19Mt8Ft7u%FJujO%eIINAcUbc}!l0V&p+D@|Z2&oLPs zGXl{^KrY5}NR+$RQsViuvnfs70`cZ{|^_ zmZSYtgLI5?eVyK}h zk(bhj#LhI8k73B<6J$bgh#&&=$-MkjHn5V}kUN485Rynt;E;g!+D#tSFVT}?JD3+Z z%%FEW$E95)ZV4uEL`R%xn{#m25VqiyQ09e6NAwXw5sL{N3e4U+QQB9j*n-V#$ZTTL z&v@!>+yfIhq72Xk)~3Q_A`-V*1Jhz24v|EF2y9;DDhkL(FcY{UIcj`^2%JNL8ZB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X4M^hI(&_xR@}0tAV)g%DS%P&cQr+GF0000 \ 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 0000000000000000000000000000000000000000..fbb298cd92ca487d5cd567a6935785207beb59a9 GIT binary patch literal 15086 zcmeHO4UAPs6~6pPwXp?5trTk58mqP1gb-tmMnTc|muk{BjT#LVZEgKYHKsPzXt$=e zV3prxVS!yrX(_apzaoES%>uR*Dcdd!loq-`LCQZ{+QRPrJAU7pnY-`3-Meq!hulBspc%D~LVV?(iUJKq0Le1ar=If)XZNG})CByD0KmcbTVKiv1p zA*jex>a^Q99Cj? z_vv(r3D|=9AC_px4Df&}4o!7(y9CR>Y}@t<_Dr1lu{&AL>?{6c@G$S=!0wAgf#Q!| znkemmfxK(_XZHKQcTfCPz`y7^;ExjdN877Zw-WsPj`~J^SZ1=|nRW6G&%J9epbuQr zfPdj9vhg=hGx%x8!~`DwsVEq$q`-D)KglzHS6d-p=E@}9;O)>g274og_Bf+D? zU=LrCu;C{Xz4#}IwpUB^${bU_ct76%Sc1i$6~A_%;fZ{a?{f2zhX0jX37#4$(YDDF zA8&$Pw5wfo|0foC_mD)p7fASzuY+&!PCk@}GWmd9{0^Y{A>eTraK#7LNwlj@d5X4F zVjS*={Hr8>VQISzNW)M6N&O(Ef^-(RW&tC4SpHRvftk(B4-X;9uS}4 zQrk-WY8RL?@#VWO7k<*E?m-8m9W`0_$&X(**w}JjyUN2~Iq_4+A?I-QO$I-0LH#P+ z(~7U1n;od`!Pd%(ANsAa)u({p%xNyZ4gYml@%B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10*gxA=|K5-b@l?GI=BKg}cdWc;Zgq`v@X>Rdh*djNh7&S<)PMJ|1g z8T2+>|5F{YuzswxKZNJ!?lL3T4*h2yvq$u8Uu$l0!!J?GVw1m2^8;3AILGOQ{RQF= zpS`tk`qp-$*Z-c-57+%5zb~ZRsPijtfWe$myX78}UdV^)JmdCUbLHorc@7qRaBodw zo4-A}1>6fF51bO`k6XIX&N+#8(_SKT1-I|mHyGe;l? z?A35SW}mMAp45uf$ikm{xkOw3*l|V-{YJZ=knn|jb$(%t5aGNZ&+qDme6OC-cm(>& z+1|+13YR^tdqX;-IMoZ{bAQ(ZtZtI)?c}6z4frvWrcn|TVRB`Q#oJO%#Otg8#Mxf|uQUFXEz ztS_8>;al%+_J#T$6pmf2_Cot*>0WPLKWuwM=~hE`YX@PU@Mg?Y-@+a#&qrFDRJ+7| zN1xPlKBFyl-r5Q5H9oZy`+W1w8R^MrL!ZL^Vq&6gJNq{6*^j|OTKG0T*r03TVEGtb zi_j-VjSori%vX%hRo|D`rQ^e31r46XaPr-M@kGKm;*(1vnQKL>deKk09uZfH{ODkspPALf}sTs+&Ma&_Z^c2V;b#HF83(a(C@1bF|m96ll-0$BIwe<2TG@;pX2-{GWg7zF)M}{f`7<3mvom(msLT{6Xpa z*ptqP*PyTH1N4Gt5SMelLO=Z95nU^D&VYV|TyJ768?ODHoG>H!$9 zanJ$mJMNsVvS7RwAzuI!A(AqD)bNcN1%AQA@z9#nD01sJNgm+>aw*4;~H@)8g literal 0 HcmV?d00001 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?.username} + {site?.name} {" "} ยท Powered by{" "}

+ {site?.connected_accounts && ( +
+ {site?.connected_accounts.map((account, index) => ( + + ))} +
+ )}
{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} +}