-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add current user in editor header, fix permissions
- Loading branch information
1 parent
3bec97a
commit ffc54d3
Showing
6 changed files
with
186 additions
and
63 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}); |
84 changes: 84 additions & 0 deletions
84
packages/app/src/components/Editor/Header/CurrentUser/CurrentUser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any> | null; | ||
} | ||
|
||
export function EditorHeaderCurrentUser(props: CurrentUserBarProps) { | ||
const initials = (user: Models.User<any>) => { | ||
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 ( | ||
<Show | ||
fallback={ | ||
<form action={signupWithGithub} method={'post'}> | ||
<Button | ||
variant={'ghost'} | ||
theme={'secondary'} | ||
size={'sm'} | ||
type={'submit'} | ||
loading={isSignup.pending} | ||
> | ||
Signup with Github | ||
</Button> | ||
</form> | ||
} | ||
when={props.user} | ||
> | ||
{user => ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger | ||
// @ts-expect-error TOOD: Fix @codeui/kit types | ||
as={triggerProps => ( | ||
<Button | ||
size={'sm'} | ||
{...triggerProps} | ||
class={currentUser} | ||
variant={'ghost'} | ||
theme={'secondary'} | ||
/> | ||
)} | ||
> | ||
<span class={badge}>{initials(user())}</span> | ||
<Icon name={'keyboard_arrow_down'} /> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuItem | ||
name="logout" | ||
as={'button'} | ||
onClick={() => { | ||
logoutAction().then(() => window.location.reload()); | ||
}} | ||
> | ||
Logout | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
)} | ||
</Show> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters