Skip to content

Commit

Permalink
feat(liveshare): improve icons and ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Apr 23, 2023
1 parent 0aa174f commit e3c9a42
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<EditorBaseRenderBarApplication />
<EditorBaseRenderBarWifi />
</div>
<div class="flex items-center gap-3">
<div class="flex items-center gap-5">
<EditorBaseRenderBarLiveshare />
<EditorBaseRenderBarDate />
<EditorBaseRenderBarFullscreen />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<template>
<div v-if="Object.entries(presence).length > 0" class="flex cursor-pointer items-center gap-2 bg-theme-background-3 px-2">
<div v-for="[index, [user]] in Object.entries(presence)" :key="index" class="p-1" :style="{ backgroundColor: user.color }">
<img v-if="user.avatar_url" class="bg-cover w-5 h-5 rounded-full" :src="user.avatar_url">
<p v-else class="font-bold font-raleway">{{ user.id.substring(0, 1).toUpperCase() }}</p>
</div>
<p>{{ Object.entries(presence).length }} / {{ LIVESHARE.presenceLimit }}</p>
<div v-if="presence.length > 0" :style="[LIVESHARE.lastUpdatedColor ? { border: `1px solid ${LIVESHARE.lastUpdatedColor}`} : {}]" class="flex px-2 cursor-pointer items-center gap-2" @click.prevent.stop="ABSOLUTE.modal.presence.info = true">
<div :style="{ backgroundColor: '#FF0000'}" class="rounded-full w-3 h-3" />
<p>{{ t('editor.presence.bar.liveshare')}}</p>
</div>
</template>

<script setup lang="ts">
import { useAbsoluteStore } from '@/store/absolute';
import { useLiveshareStore } from '@/store/liveshare';
import { computed } from 'vue';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
const LIVESHARE = useLiveshareStore()
const ABSOLUTE = useAbsoluteStore()
const { t } = useI18n()
const presence = computed({
get() {
return Object.entries(LIVESHARE.presence);
},
set(value) {
return value
}
});
// TODO: resolve reactivity for this
const presence = computed(() => LIVESHARE.presence)
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
>
<EditorAbsoluteHeader :title="t('editor.presence.create.title')" @close="onClose" />
<p>{{ t('editor.presence.create.description') }}</p>
<div class="flex flex-col sm:flex-row gap-5 w-full items-center justify-between">
<button :class="[wizard === 'create' ? 'bg-theme-background-3' : 'bg-theme-background-2']" class="flex-1 py-2 w-full" @click="wizard = 'create'">Criar</button>
<button :class="[wizard === 'enter' ? 'bg-theme-background-3' : 'bg-theme-background-2']" class="flex-1 py-2 w-full" @click="wizard = 'enter'">Entrar</button>
<div v-if="!key" class="flex flex-col sm:flex-row gap-5 w-full items-center justify-between">
<Button :class="[wizard === 'create' ? 'bg-theme-background-3' : 'bg-theme-background-2']" class="flex-1 py-2 w-full" @click="wizard = 'create'">{{ t('editor.presence.info.create') }}</Button>
<Button :class="[wizard === 'enter' ? 'bg-theme-background-3' : 'bg-theme-background-2']" class="flex-1 py-2 w-full" @click="wizard = 'enter'">{{ t('editor.presence.info.enter') }}</Button>
</div>
<div v-if="wizard === 'create'" class="flex flex-col gap-2">
<h2 class="text-lg font-bold font-poppins">{{ t('editor.presence.create.new') }}</h2>
<button v-if="!key" class="w-full p-2 bg-theme-background-2" @click.prevent.stop="onCreateRoom">{{ t('editor.presence.create.button') }}</button>
<div v-if="key" class="flex w-full items-center rounded-full p-1 justify-between">
<p class="font-bold text-lg">{{ key }}</p>
<button class="wb-icon" @click.prevent.stop="onCopy">
<IconCopyLink class="w-6 h-6" />
</button>
</div>
<Button v-if="!key" class="w-full p-2 bg-theme-background-2" @click.prevent.stop="onCreateRoom">{{ t('editor.presence.create.button') }}</Button>
<EditorProjectPresenceKey :id="key" />
</div>
<div v-if="wizard === 'enter'" class="flex flex-col gap-2">
<h2 class="text-lg font-bold font-poppins">{{ t('editor.presence.create.enterInput') }}</h2>
Expand All @@ -32,11 +27,10 @@

<script setup lang="ts">
import { useAbsoluteStore } from '@/store/absolute'
import { useClipboard } from '@vueuse/core'
import { usePlugin } from 'better-write-plugin-core'
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useToast } from 'vue-toastification'
import { useToast } from 'vue-toastification'
const ABSOLUTE = useAbsoluteStore()
Expand All @@ -47,7 +41,6 @@
const { t } = useI18n()
const plugin = usePlugin()
const toast = useToast()
const { copy, isSupported } = useClipboard({ source: key })
onMounted(() => {
plugin.on('plugin-presence-room-create-key', (id: string) => {
Expand All @@ -62,7 +55,11 @@
}
const onJoinRoom = () => {
if(room.value.length !== 30 || room.value === key.value) return
if(room.value.length !== 30 || room.value === key.value) {
toast.error(t('toast.generics.error'))
return
}
plugin.emit('plugin-presence-room-join', room.value)
Expand All @@ -72,12 +69,4 @@
const onClose = () => {
ABSOLUTE.modal.presence.createOrJoin = false
}
const onCopy = async () => {
if(isSupported.value) {
await copy()
toast.success(t('toast.generics.copy'))
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<Modal @close="onClose">
<div class="flex items-center justify-center w-full h-screen bg-modal">
<div
ref="main"
class="left-0 top-0 p-5 flex z-max flex-col w-full bg-rgba-blur lg:w-1/2 h-full lg:h-3/4 bg-theme-background-1 wb-text wb-scroll overflow-y-auto rounded shadow-2xl wb-scroll"
>
<EditorAbsoluteHeader :title="t('editor.presence.info.title') + ` - ${presence.length} / ${LIVESHARE.presenceLimit}`" @close="onClose" />
<div v-if="presence.length > 0" class="flex mt-5 flex-col gap-5" @click.prevent.stop="ABSOLUTE.modal.presence.info = true">
<h2 class="text-lg font-bold">Chave da Sala:</h2>
<EditorProjectPresenceKey :id="LIVESHARE.roomKey" />
<h2 class="text-lg font-bold">Usuários Conectados:</h2>
<div v-for="[index, [user]] in presence" :key="index" class="flex border-3 rounded-full shadow-lg p-2 justify-between items-center w-full" :style="{ borderColor: user.color }">
<div class="flex items-center justify-between w-full gap-5">
<div class="flex gap-2">
<img v-if="user.avatar_url" class="bg-cover rounded-full h-8 w-8" :src="user.avatar_url">
<p class="flex items-center truncate justify-center font-bold font-raleway rounded-full wb-text text-sm h-8 sm:text-lg">{{ user.id }}</p>
</div>
<EditorProjectPresenceInformationType :type="user.type" />
</div>
</div>
</div>
<Button @click="plugin.emit('plugin-presence-room-leave', LIVESHARE.roomKey)">{{ t('editor.presence.info.leave') }}</Button>
</div>
</div>
</Modal>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useAbsoluteStore } from '@/store/absolute';
import { useLiveshareStore } from '@/store/liveshare';
import { computed } from 'vue';
import { usePlugin } from 'better-write-plugin-core';
const ABSOLUTE = useAbsoluteStore()
const LIVESHARE = useLiveshareStore()
const { t } = useI18n()
const plugin = usePlugin()
const presence = computed({
get() {
return Object.entries(LIVESHARE.presence);
},
set(value) {
return value
}
});
const onClose = () => {
ABSOLUTE.modal.presence.info = false
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div class="text-center font-raleway">
<p v-if="type === 'owner'" :style="{ backgroundColor: '#500', borderColor: '#F00', color: '#F00'}" class="px-2 font-bold border-2 rounded-full">{{ t('editor.presence.type.owner') }}</p>
<p v-if="type === 'visit'" :style="{ backgroundColor: '#9A0', borderColor: '#FF0', color: '#FF0'}" class="px-2 font-bold border-2 rounded-full">{{ t('editor.presence.type.visit') }}</p>
</div>
</template>

<script setup lang="ts">
import { useI18n } from "vue-i18n"
defineProps<{
type: 'owner' | 'visit'
}>()
const { t } = useI18n()
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div v-if="props.id" class="flex w-full items-center rounded-full p-1 justify-between">
<p class="font-bold text-lg">{{ props.id }}</p>
<button class="wb-icon" @click.prevent.stop="onCopy">
<IconCopyLink class="w-6 h-6" />
</button>
</div>
</template>

<script setup lang="ts">
import { useClipboard } from "@vueuse/core"
import { useI18n } from "vue-i18n"
import { useToast } from "vue-toastification"
const props = defineProps<{
id: string
}>()
const toast = useToast()
const { t } = useI18n()
const onCopy = async () => {
const { copy, isSupported } = useClipboard({ source: props.id })
if(isSupported.value) {
await copy()
toast.success(t('toast.generics.copy'))
}
}
</script>
2 changes: 2 additions & 0 deletions packages/better-write-app/src/store/liveshare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const useLiveshareStore = defineStore('liveshare', {
presence: {},
presenceLimit: 5,
ownerKey: undefined,
roomKey: undefined,
lastUpdatedColor: undefined,
}
},
actions: {
Expand Down
7 changes: 6 additions & 1 deletion packages/better-write-app/src/use/storage/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY

export const s = createClient(supabaseUrl, supabaseAnonKey, {
auth: { storageKey: '__BW__' }
auth: { storageKey: '__BW__' },
realtime: {
params: {
eventsPerSecond: 10
}
}
})

export const getSupabaseUser = async () => {
Expand Down
9 changes: 4 additions & 5 deletions packages/better-write-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default ({ mode }) => {
}),
windiCSS(),
CSSFontaine.vite({
fallbacks: ['Raleway', 'Poppins', 'BlinkMacSystemFont', 'Segoe UI', 'Helvetica Neue', 'Arial', 'Noto Sans'],
fallbacks: ['BlinkMacSystemFont', 'Segoe UI', 'Helvetica Neue', 'Arial', 'Noto Sans'],
resolvePath: id => new URL('.' + id, import.meta.url),
}),
viteSitemap({
Expand All @@ -76,9 +76,8 @@ export default ({ mode }) => {
viteAutoImport({
dts: './imports.d.ts',
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/, /\.vue\?vue/, // .vue
/\.md$/ // .md
/\.[tj]sx?$/,
/\.vue$/, /\.vue\?vue/
],
imports: [
'vue',
Expand All @@ -88,7 +87,7 @@ export default ({ mode }) => {
vitePWA({
base: '/',
registerType: 'prompt',
includeAssets: fg.sync('**/*.{png,svg,json,ico,txt,xml,ttf}', { cwd: resolve(__dirname, 'public') }),
includeAssets: fg.sync('**/*.{png,svg,json,mp3,ico,txt,xml,ttf}', { cwd: resolve(__dirname, 'public') }),
manifest: {
name: 'Better Write',
short_name: 'Better Write',
Expand Down
25 changes: 25 additions & 0 deletions packages/better-write-languages/src/en-US/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,29 @@ export default {
},
},
},
presence: {
type: {
owner: 'Owner',
visit: 'Visitant',
},
bar: {
liveshare: 'Sharing...',
},
create: {
title: 'Live Share',
description:
'Share your project with others in real time to build an experience together!',
button: 'Create Room',
or: 'Or',
new: 'Create Room:',
enterInput: 'Enter Room:',
enterPlaceholder: 'vCAQe6FD3D...',
},
info: {
enter: 'Enter',
create: 'Create',
title: 'Share Room',
leave: 'Leave Room',
},
},
}
13 changes: 13 additions & 0 deletions packages/better-write-languages/src/pt-BR/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,13 @@ export default {
},
},
presence: {
type: {
owner: 'Dono',
visit: 'Visitante',
},
bar: {
liveshare: 'Compartilhando...',
},
create: {
title: 'Compartilhamento',
description:
Expand All @@ -857,5 +864,11 @@ export default {
enterInput: 'Entre em uma sala:',
enterPlaceholder: 'vCAQe6FD3D...',
},
info: {
enter: 'Entrar',
create: 'Criar',
title: 'Sala Compartilhada',
leave: 'Sair da Sala',
},
},
}
Loading

0 comments on commit e3c9a42

Please sign in to comment.