Skip to content

Commit

Permalink
allow setting of twitter handle
Browse files Browse the repository at this point in the history
  • Loading branch information
codyzu committed Jul 17, 2023
1 parent ec88687 commit 0c0181f
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 13 deletions.
6 changes: 4 additions & 2 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ service cloud.firestore {

allow update: if request.auth != null
&& request.auth.uid == resource.data.uid
&& request.resource.data.diff(resource.data).affectedKeys().hasOnly(['original', 'pages', 'rendered', 'title', 'notes', 'username']);
&& request.resource.data.diff(resource.data).affectedKeys().hasOnly(['original', 'pages', 'rendered', 'title', 'notes', 'username', 'twitterHandle']);

allow delete: if request.auth != null
&& request.auth.uid == resource.data.uid;
}
match /users/{userId} {
allow write: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId
&& request.resource.data.keys().hasAll(['username', 'twitterHandle'])
&& request.resource.data.keys().hasOnly(['username', 'twitterHandle']);
allow read: if request.auth != null && request.auth.uid == userId;
}
match /sessions/{sessionId} {
Expand Down
17 changes: 10 additions & 7 deletions functions/src/presentation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PresentationCreate = {
notes: Note[];
uid: string;
username: string;
twitterHandle: string;
};

export type PresentationUpdate =
Expand All @@ -22,6 +23,7 @@ export type PresentationUpdate =
}
| {
username: string;
twitterHandle: string;
}
| {
title: string;
Expand All @@ -34,11 +36,12 @@ export type PresentationUpdate =
notes: Note[];
};

export type PresentationData = PresentationCreate &
PresentationUpdate & {
// Thumb: string;
// TODO: use this in function metadata
twitterHandle?: string;
thumbIndex?: number;
};
export type PresentationData = PresentationCreate & {
original: string;
rendered: Date;

// Thumb: string;
// TODO: use this in function metadata
thumbIndex?: number;
};
export type PresentationDoc = Doc & PresentationData;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "pnpm run emulators:exec --import test-data 'pnpm run dev:start'",
"dev": "pnpm run emulators:exec --ui --import test-data 'pnpm run dev:start'",
"dev:update": "pnpm run emulators:exec --import test-data 'pnpm run dev:start' --export-on-exit",
"dev:start": "vite --mode emulator",
"build": "tsc && vite build",
Expand Down
1 change: 1 addition & 0 deletions src/components/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type User = {

export type UserDoc = {
username?: string;
twitterHandle?: string;
};

export const UserContext = createContext<{
Expand Down
1 change: 1 addition & 0 deletions src/pages/Audience.Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ beforeAll(async () => {
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'],
notes: [],
title: 'test presentation',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
});

Expand Down
3 changes: 3 additions & 0 deletions src/pages/Home.Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ beforeAll(async () => {
pages: [],
notes: [],
title: 'home1',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
await updateDoc(doc(firestore, 'presentations', 'home-p1'), {
notes: [],
Expand All @@ -54,6 +55,7 @@ beforeAll(async () => {
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'],
notes: [],
title: 'home2',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
await updateDoc(doc(firestore, 'presentations', 'home-p2'), {
notes: [],
Expand All @@ -69,6 +71,7 @@ beforeAll(async () => {
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'],
notes: [],
title: 'home3',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
await updateDoc(doc(firestore, 'presentations', 'home-p3'), {
notes: [],
Expand Down
1 change: 1 addition & 0 deletions src/pages/Presentation.Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ beforeAll(async () => {
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'],
notes: [],
title: 'test presentation',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
});

Expand Down
1 change: 1 addition & 0 deletions src/pages/Speaker.Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ beforeAll(async () => {
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'],
notes: [],
title: 'test presentation',
twitterHandle: '@doesnotexist',
} satisfies PresentationCreate);
});

Expand Down
1 change: 1 addition & 0 deletions src/pages/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function Export() {
created: new Date(),
uid: auth.currentUser!.uid,
username: userData?.username ?? '',
twitterHandle: userData?.twitterHandle ?? '',
pages: [],
notes: [],
title: '',
Expand Down
34 changes: 32 additions & 2 deletions src/pages/UserPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function UserPreferences() {
userPresentationsSnapshot.docs.map(async (presentation) =>
updateDoc(doc(firestore, 'presentations', presentation.id), {
username: userData.username!,
twitterHandle: userData.twitterHandle!,
} satisfies PresentationUpdate),
),
);
Expand All @@ -68,12 +69,20 @@ export default function UserPreferences() {
return (
<DefaultLayout title="User Preferences">
<div className="max-w-screen-sm mx-auto grid grid-cols-[auto_1fr] gap-4 w-full">
<label className="flex items-center justify-end">Email:</label>
<div className="flex items-center justify-end">Email:</div>
<div className="">{user?.email ?? ''}</div>
<label className="flex items-center justify-end">Username:</label>
<label
id="username-label"
className="flex flex-col items-end justify-center"
>
<div>Username:</div>
<div className="text-xs">(optional)</div>
</label>
<input
aria-labelledby="username-label"
className="input flex-grow"
value={userData.username ?? ''}
placeholder="your name"
onChange={(event) => {
setSaveState('dirty');
setUserData((currentUser) => ({
Expand All @@ -83,6 +92,27 @@ export default function UserPreferences() {
void save();
}}
/>
<label
id="twitter-label"
className="flex flex-col items-end justify-center"
>
<div>Twitter handle:</div>
<div className="text-xs">(optional)</div>
</label>
<input
aria-labelledby="twitter-label"
className="input flex-grow"
value={userData.twitterHandle ?? ''}
placeholder="@yourhandle"
onChange={(event) => {
setSaveState('dirty');
setUserData((currentUser) => ({
...currentUser,
twitterHandle: event.target.value,
}));
void save();
}}
/>
<SaveIndicator saveState={saveState} />
</div>
</DefaultLayout>
Expand Down
2 changes: 1 addition & 1 deletion test-data/auth_export/accounts.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"kind":"identitytoolkit#DownloadAccountResponse","users":[{"localId":"8xv74jU1Ac5srObCVP2QphcQ6emp","createdAt":"1689154854814","lastLoginAt":"1689160869623","displayName":"","photoUrl":"","passwordHash":"fakeHash:salt=fakeSaltQvugFwADIS9rqdVcbniJ:password=123456","salt":"fakeSaltQvugFwADIS9rqdVcbniJ","passwordUpdatedAt":1689160862685,"providerUserInfo":[{"providerId":"password","email":"test@doesnotexist.com","federatedId":"test@doesnotexist.com","rawId":"test@doesnotexist.com","displayName":"","photoUrl":""}],"validSince":"1689160862","email":"test@doesnotexist.com","emailVerified":false,"disabled":false,"lastRefreshAt":"2023-07-12T11:21:09.623Z"}]}
{"kind":"identitytoolkit#DownloadAccountResponse","users":[{"localId":"8xv74jU1Ac5srObCVP2QphcQ6emp","createdAt":"1689154854814","lastLoginAt":"1689590441148","displayName":"","photoUrl":"","passwordHash":"fakeHash:salt=fakeSaltQvugFwADIS9rqdVcbniJ:password=123456","salt":"fakeSaltQvugFwADIS9rqdVcbniJ","passwordUpdatedAt":1689590425137,"providerUserInfo":[{"providerId":"password","email":"test@doesnotexist.com","federatedId":"test@doesnotexist.com","rawId":"test@doesnotexist.com","displayName":"","photoUrl":""}],"validSince":"1689590425","email":"test@doesnotexist.com","emailVerified":false,"disabled":false,"lastRefreshAt":"2023-07-17T10:40:41.148Z"}]}
Binary file not shown.
Binary file modified test-data/firestore_export/all_namespaces/all_kinds/output-0
Binary file not shown.
Binary file not shown.

0 comments on commit 0c0181f

Please sign in to comment.