Skip to content

Commit

Permalink
feat: dropbox storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed May 24, 2023
1 parent 02892c1 commit f5e21f7
Show file tree
Hide file tree
Showing 25 changed files with 365 additions and 38 deletions.
3 changes: 3 additions & 0 deletions packages/app/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ VITE_GOOGLE_FONTS_MAX_FONTS=
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=

// Dropbox SDK
VITE_DROPBOX_APP_KEY=

// Sentry
VITE_SENTRY_DSN=

Expand Down
2 changes: 2 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"destr": "1.2.2",
"docx": "7.5.0",
"drauu": "0.3.2",
"dropbox": "10.34.0",
"file-saver": "2.0.5",
"floating-vue": "2.0.0-beta.20",
"hast": "1.0.0",
Expand Down Expand Up @@ -155,6 +156,7 @@
"@vueuse/components",
"@milkdown/utils",
"docx",
"dropbox",
"es5-ext/global",
"file-saver",
"jiti",
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/components/icons/IconDropbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="1.18em" height="1em" viewBox="0 0 256 218"><path fill="#0061FF" d="M63.995 0L0 40.771l63.995 40.772L128 40.771zM192 0l-64 40.775l64 40.775l64.001-40.775zM0 122.321l63.995 40.772L128 122.321L63.995 81.55zM192 81.55l-64 40.775l64 40.774l64-40.774zM64 176.771l64.005 40.772L192 176.771L128.005 136z"></path></svg>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
:text="t('editor.bar.supabase.save')"
@action="onSaveProjectSupabase"
/>
<EditorHeaderItem
v-if="PROJECT.name !== env.projectEmpty() && AUTH.account.dropboxAccessToken"
:text="t('editor.bar.dropbox.save')"
@action="dropbox.save"
>
<template #icon>
<IconDropbox class="w-6 h-6 mr-2" />
</template>
</EditorHeaderItem>
<EditorHeaderItemDiv v-if="PROJECT.name !== env.projectEmpty()" />
<EditorHeaderItem
v-if="
Expand Down Expand Up @@ -77,6 +86,7 @@
import { useLocalStorage } from '@/use/storage/local'
import { useSupabase } from '@/use/storage/supabase'
import { useAuthStore } from '@/store/auth'
import { useDropbox } from '@/use/storage/dropbox'
const ABSOLUTE = useAbsoluteStore()
const PROJECT = useProjectStore()
Expand All @@ -86,6 +96,7 @@
const project = useProject()
const env = useEnv()
const local = useLocalStorage()
const dropbox = useDropbox()
const { t } = useI18n()
const onSaveProject = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<section v-if="HISTORY.bar.length !== 0" class="flex z-50 wb-text items-center bg-theme-background-opacity-1 justify-between w-full">
<section v-if="HISTORY.bar.length !== 0 && PROJECT.type !== 'blank'" class="flex z-50 wb-text items-center bg-theme-background-opacity-1 justify-between w-full">
<button v-for="(item, index) in HISTORY.bar" :key="index" :class="[HISTORY.barActive === item.id ? 'bg-theme-background-2' : 'hover:bg-theme-background-opacity-1']" class="flex-1 font-bold flex justify-around items-center font-raleway min-w-12 h-10 md:(h-9)" @click.prevent.stop="history.onLoad(item)">
<div class="flex gap-2 truncate pl-2">
<CustomIcon v-if="item.customIcon" :icon="item.customIcon" />
Expand All @@ -17,9 +17,11 @@

<script setup lang="ts">
import { useHistoryStore } from '@/store/history';
import { useProjectStore } from '@/store/project';
import { useHistory } from '@/use/history'
const HISTORY = useHistoryStore()
const PROJECT = useProjectStore()
const history = useHistory()
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div v-if="!AUTH.account.dropboxAccessToken" class="flex px-2 py-1 mb-5 cursor-pointer bg-theme-background-2 justify-between items-center w-full wb-text" @click.prevent.stop="dropbox.connect">
<button>
<IconDropbox class="w-7 h-7" />
</button>
<p class="font-poppins font-bold">Conectar</p>
</div>
<div v-else class="flex px-2 py-1 mb-5 cursor-pointer bg-theme-background-2 justify-between items-center w-full wb-text" @click.prevent.stop="dropbox.load">
<button>
<IconDropbox class="w-7 h-7" />
</button>
<p class="font-poppins font-bold">Carregar</p>
</div>
</template>

<script setup lang="ts">
import { useAuthStore } from '@/store/auth';
import { useDropbox } from '@/use/storage/dropbox';
const AUTH = useAuthStore()
const dropbox = useDropbox()
</script>
36 changes: 36 additions & 0 deletions packages/app/src/components/page/editor/vault/EditorVaultList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@
<div
class="flex flex-col justify-start items-stretch gap-2 bg-black-opacity p-5 max-h-100 wb-scroll overflow-y-auto"
>
<EditorVaultDropbox v-if="VAULT.dropboxFiles.length === 0" />
<div
v-for="(file, index) in VAULT.dropboxFiles"
:key="index"
class="flex flex-col w-full flex-wrap justify-start md:justify-between items-center bg-theme-editor-dashboard-background-main wb-text rounded my-1 shadow-binset transition-shadow hover:shadow-xl"
>
<div class="flex items-center justify-start p-1 bg-black-opacity w-full">
<div class="flex gap-2 items-center">
<div>
<IconDropbox class="w-7 h-7" />
</div>
<h2 class="text-sm font-bold">
{{ t('editor.bar.dropbox.title') }}
</h2>
</div>
</div>
<div class="flex flex-col justify-between w-full p-2">
<h2 class="text-sm font-bold text-center">{{ file.name }}</h2>
<div class="flex justify-end flex-1 mt-5 items-center w-full">
<div>
<IconDelete
class="wb-icon w-8 h-8 lg:(w-6 h-6)"
@click.prevent.stop="dropbox.deleteProject(file)"
/>
</div>
<div>
<IconEnter
class="wb-icon w-8 h-8 lg:(w-6 h-6)"
@click.prevent.stop="dropbox.loadProject(file)"
/>
</div>
</div>
</div>
</div>
<Spinner v-if="!isFetched" :width="80" :height="80" />
<div
v-for="({ document }, index) in projects"
Expand Down Expand Up @@ -67,13 +101,15 @@

<script setup lang="ts">
import { useVaultStore } from '@/store/vault'
import { useDropbox } from '@/use/storage/dropbox'
import { useSupabase } from '@/use/storage/supabase'
import { ProjectDocument, ID } from 'better-write-types'
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
const VAULT = useVaultStore()
const dropbox = useDropbox()
const supabase = useSupabase()
const { t } = useI18n()
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const useAuthStore = defineStore('auth', {
user: null,
project_id_activity: null,
multiplayer: { client: null, connect: null },
dropboxAccessToken: null,
},
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useProjectStore = defineStore('project', {
base: 'chapter',
type: 'creative',
totalPagesCreated: 0,
externalProvider: undefined,
main: {},
summary: {},
chapters: [],
Expand Down Expand Up @@ -88,6 +89,7 @@ export const useProjectStore = defineStore('project', {
payload.type === 'only-annotations' ? 'annotations' : 'chapter'
this.subject = payload.subject
this.pageLoaded = payload.pageLoaded
this.externalProvider = payload.externalProvider
this.scrollLoaded = payload.scrollLoaded
this.offsetLoaded = payload.offsetLoaded
this.totalPagesCreated = payload.totalPagesCreated
Expand Down
9 changes: 7 additions & 2 deletions packages/app/src/store/vault.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ProjectDocument } from 'better-write-types'
import { ProjectDocument, ProjectObject } from 'better-write-types'
import { files } from 'dropbox'
import { defineStore } from 'pinia'

export const useVaultStore = defineStore('vault', {
state: (): { documents?: ProjectDocument[] } => {
state: (): {
dropboxFiles: files.FileMetadataReference[]
documents?: ProjectDocument[]
} => {
return {
dropboxFiles: [],
documents: undefined,
}
},
Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/use/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const useEnv = () => {
return import.meta.env.VITE_PROJECT_EMPTY
}

const dropboxKey = (): string => {
return import.meta.env.VITE_DROPBOX_APP_KEY
}

const projectLocalStorage = () => {
return import.meta.env.VITE_LOCAL_STORAGE
}
Expand Down Expand Up @@ -87,6 +91,7 @@ export const useEnv = () => {
production,
getSentryDsn,
getProdUrl,
dropboxKey,
getCorrectLocalUrl,
storageLimitSaver,
emptyLine,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/use/initializer/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useDBInitializer = () => {

const init = async () => {
const { data } = await s.auth.getSession()

AUTH.account.user = data.session?.user ?? null

s.auth.onAuthStateChange((_, session) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/use/initializer/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import * as VUEUSE_CORE from '@vueuse/core'
import * as VUEUSE_HEAD from '@vueuse/head'
import * as VUEUSE_SOUND from '@vueuse/sound'
import { useGlobalStore } from '@/store/global'
import { useDropbox } from '../storage/dropbox'

export const usePluginInitializer = () => {
const core = useCore()
Expand Down Expand Up @@ -90,6 +91,7 @@ export const usePluginInitializer = () => {
characters: useCharacters(),
supabase: s,
router: VUEROUTER.useRouter(),
dropbox: useDropbox(),
vuerouter: VUEROUTER,
vueuse: {
core: VUEUSE_CORE,
Expand Down
Loading

0 comments on commit f5e21f7

Please sign in to comment.