Skip to content

Commit cc0b451

Browse files
committed
Add owner detail in on snippng code save
1 parent 4cc8b5c commit cc0b451

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

components/editor/SnippngCodeArea.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const SnippngCodeArea: React.FC<Props> = ({ underConstructionTheme }) => {
8383
const savedDoc = await addDoc(collection(db, "snippets"), {
8484
...dataToBeAdded,
8585
ownerUid: user.uid,
86+
owner: {
87+
displayName: user.displayName,
88+
photoURL: user.photoURL,
89+
email: user.email,
90+
},
8691
});
8792
if (savedDoc.id) {
8893
addToast({
@@ -148,6 +153,7 @@ const SnippngCodeArea: React.FC<Props> = ({ underConstructionTheme }) => {
148153
...editorConfig,
149154
uid: undefined,
150155
ownerUid: undefined,
156+
owner: undefined,
151157
});
152158
}, [editorConfig, uid, underConstructionTheme]);
153159

components/explore/PublishedThemeListing.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const PublishedThemeListing = () => {
2525
);
2626
docRef.forEach((doc) => {
2727
const theme = doc.data();
28-
if (theme.ownerUid === user?.uid) return; // filter the own themes
2928
_themes.push({
3029
...theme,
3130
uid: doc.id,

pages/snippet/[uid].tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useEffect, useState } from "react";
1313
// TODO: implement SSR
1414
const SavedSnippet = () => {
1515
const router = useRouter();
16-
const { setEditorConfig } = useSnippngEditor();
16+
const { editorConfig, setEditorConfig } = useSnippngEditor();
1717

1818
const [notFound, setNotFound] = useState(false);
1919
const [loadingConfig, setLoadingConfig] = useState(true);
@@ -53,6 +53,7 @@ const SavedSnippet = () => {
5353
...defaultEditorConfig,
5454
uid: undefined,
5555
ownerUid: undefined,
56+
owner: undefined,
5657
});
5758
};
5859
}, [router.isReady]);
@@ -83,7 +84,45 @@ const SavedSnippet = () => {
8384
</Layout>
8485
);
8586

86-
return <Layout>{loadingConfig ? <Loader /> : <SnippngCodeArea />}</Layout>;
87+
return (
88+
<Layout>
89+
{loadingConfig ? (
90+
<Loader />
91+
) : (
92+
<>
93+
<div className="my-4 max-w-3xl md:flex md:items-start md:justify-between md:space-x-5 lg:max-w-7xl">
94+
<div className="flex items-start space-x-5">
95+
<div className="flex-shrink-0">
96+
<div className="relative">
97+
<img
98+
className="h-14 w-14 rounded-full border-[1px] dark:border-white border-zinc-900"
99+
src={editorConfig?.owner?.photoURL || ""}
100+
alt=""
101+
/>
102+
<span
103+
className="absolute inset-0 rounded-full shadow-inner"
104+
aria-hidden="true"
105+
/>
106+
</div>
107+
</div>
108+
<div>
109+
<h1 className="text-xl items-center inline-flex font-bold text-zinc-900 dark:text-white">
110+
{editorConfig?.owner?.displayName || "Snippng user"}{" "}
111+
<span className="inline-flex items-center ml-1.5 rounded-sm dark:bg-indigo-600 bg-indigo-100 h-[15px] py-1.5 px-1 text-[10px] dark:text-indigo-100 text-indigo-600 border-[1px] border-indigo-600">
112+
Author
113+
</span>
114+
</h1>
115+
<p className="text-xs text-zinc-500 dark:text-zinc-300">
116+
{editorConfig?.owner?.email || "Snippng user email"}
117+
</p>
118+
</div>
119+
</div>
120+
</div>
121+
<SnippngCodeArea />
122+
</>
123+
)}
124+
</Layout>
125+
);
87126
};
88127

89128
export default SavedSnippet;

types/editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type SnippngWindowControlsType =
5454

5555
export interface SnippngEditorConfigInterface {
5656
ownerUid?: string;
57+
owner?: Pick<User, "displayName" | "email" | "photoURL">;
5758
uid?: string;
5859
watermark?: boolean;
5960
code: string;

utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export const getExportableConfig = (
175175
deepClonedConfig.bgImageVisiblePatch = null;
176176
delete deepClonedConfig.uid;
177177
delete deepClonedConfig.ownerUid;
178+
delete deepClonedConfig.owner;
178179
const exportableConfig: SnippngExportableConfig = deepClonedConfig;
179180
return exportableConfig;
180181
};

0 commit comments

Comments
 (0)