diff --git a/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.css.ts b/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.css.ts new file mode 100644 index 0000000..d5fc02c --- /dev/null +++ b/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.css.ts @@ -0,0 +1,18 @@ +import {style} from '@vanilla-extract/css'; + +export const badge = style({ + width: '28px', + height: '28px', + display: 'inline-flex', + alignItems: 'center', + justifyContent: 'center', + textAlign: 'center', + fontSize: '13px !important', + background: '#076a6e', + color: 'white', + borderRadius: '9999px', +}); + +export const currentUser = style({ + fontSize: '14px !important', +}); diff --git a/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.tsx b/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.tsx new file mode 100644 index 0000000..830d1f3 --- /dev/null +++ b/packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.tsx @@ -0,0 +1,84 @@ +import {Icon} from '#ui/components/Icon'; +import { + Button, + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@codeui/kit'; +import {useAction, useSubmission} from '@solidjs/router'; +import type {Models} from 'appwrite'; +import {Show} from 'solid-js'; +import {logout, signupWithGithub} from '~/lib/session'; +import {badge, currentUser} from './CurrentUser.css'; +export interface CurrentUserBarProps { + user: Models.User | null; +} + +export function EditorHeaderCurrentUser(props: CurrentUserBarProps) { + const initials = (user: Models.User) => { + if (user.name) { + const [firstName, lastName] = user.name.split(' '); + return [firstName, lastName] + .filter(Boolean) + .map(str => str.charAt(0)) + .join(''); + } else { + return '?'; + } + }; + + const logoutAction = useAction(logout); + + const isSignup = useSubmission(signupWithGithub); + + return ( + + + + } + when={props.user} + > + {user => ( + + ( + - + + + )} - - + + + +
( {scratch().name}.yml - - ( - - )} - > - - - -
{ - e.preventDefault(); - const data = new FormData(e.target as HTMLFormElement); - renamingScratch( - editor.remoteId!, - data.get('name') as string, - ).finally(() => { - setEditing(false); - }); - }} + + + ( + + )} > - -
- -
- -
-
+ + + +
{ + e.preventDefault(); + const data = new FormData(e.target as HTMLFormElement); + renamingScratch( + editor.remoteId!, + data.get('name') as string, + ).finally(() => { + setEditing(false); + }); + }} + > + +
+ +
+ +
+ +
)} diff --git a/packages/app/src/store/editor/editor.store.ts b/packages/app/src/store/editor/editor.store.ts index a3fae4e..243c4ba 100644 --- a/packages/app/src/store/editor/editor.store.ts +++ b/packages/app/src/store/editor/editor.store.ts @@ -96,14 +96,15 @@ export const EditorStore = defineStore(() => ({ }; }) .extend((_, context) => { + const editorContext = useContext(EditorContext)!; + context.hooks.onInit(() => { - const context = useContext(EditorContext)!; // Support reactivity when using hybrid routing createEffect( on( - () => context.source, + () => editorContext.source, source => { - _.initEditSession(context.source).then(); + _.initEditSession(editorContext.source).then(); }, // {defer: true}, ), @@ -111,13 +112,22 @@ export const EditorStore = defineStore(() => ({ createEffect( on( - () => context.remoteId, + () => editorContext.remoteId, remoteId => { _.set('remoteId', remoteId); }, ), ); }); + + return { + scratch() { + return editorContext.scratch?.(); + }, + canEditCurrent() { + return editorContext.scratch?.()?.canEdit === true; + }, + }; }) .extend( withProxyCommands<{