-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
VITE_PROJECT_EMPTY=__NOT_CREATED__ | ||
VITE_PROJECT_EMPTY=__NOT_CREATED__ | ||
VITE_LOCAL_STORAGE=__BETTER_WRITE__ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<InjectButtonInstance class="wb-aside-button" @click.prevent="onSaveProject"> | ||
{{ t('editor.aside.project.load.title') }} | ||
</InjectButtonInstance> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n } from 'vue-i18n' | ||
import { useLocalStorage } from '@/use/storage/local' | ||
import { useStore } from 'vuex' | ||
import { nextTick } from 'vue' | ||
const store = useStore() | ||
const onSaveProject = async () => { | ||
const context = useLocalStorage().getProject() | ||
store.commit('project/load', context.project) | ||
await nextTick | ||
store.commit('context/load', store.state.project.pages[0]) | ||
} | ||
const { t } = useI18n() | ||
</script> |
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,22 @@ | ||
<template> | ||
<InjectButtonInstance class="wb-aside-button" @click.prevent="onSaveProject"> | ||
{{ t('editor.aside.project.save.title') }} | ||
</InjectButtonInstance> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n } from 'vue-i18n' | ||
import { useLocalStorage } from '@/use/storage/local' | ||
import { useStore } from 'vuex' | ||
const store = useStore() | ||
const onSaveProject = () => { | ||
useLocalStorage().setProject({ | ||
project: store.state.project, | ||
editor: store.state.editor, | ||
}) | ||
} | ||
const { t } = useI18n() | ||
</script> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Callback } from '@/types/utils' | ||
|
||
export const useIndexedDB: Callback<any> = () => { | ||
const supports = (): boolean => { | ||
return window.indexedDB ? true : false | ||
} | ||
|
||
const open = ( | ||
obj: Record<string, any>, | ||
cb?: Callback<any> | ||
): IDBOpenDBRequest => { | ||
if (!supports()) { | ||
alert('kekw') | ||
} | ||
|
||
const db = window.indexedDB.open(obj.name, obj.version) | ||
|
||
db.onerror = (event: any) => { | ||
console.error(`Database error: ${event.target.errorCode}`) | ||
} | ||
|
||
db.onsuccess = (event: any) => {} | ||
|
||
;(db as any).onupgradeneeded((event: any) => { | ||
const database = event.target.result | ||
|
||
const _store = database.createObjectStore('Contacts', { | ||
autoIncrement: true, | ||
}) | ||
|
||
let index = _store.createIndex('email', 'email', { | ||
unique: true, | ||
}) | ||
|
||
const txn = database.transaction('Contacts', 'readwrite') | ||
|
||
// get the Contacts object store | ||
const store = txn.objectStore('Contacts') | ||
// | ||
let query = store.put({ email: 'email', test: 'test' }) | ||
|
||
// handle success case | ||
query.onsuccess = function (event: any) { | ||
console.log(event) | ||
} | ||
|
||
// handle the error case | ||
query.onerror = function (event: any) { | ||
console.log(event.target.errorCode) | ||
} | ||
|
||
// close the database once the | ||
// transaction completes | ||
txn.oncomplete = function () { | ||
database.close() | ||
} | ||
}) | ||
|
||
return db | ||
} | ||
|
||
const createTables = (obj: Record<any, any>) => { | ||
open(obj).onupgradeneeded | ||
} | ||
|
||
return { open } | ||
} |
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,23 @@ | ||
import { ProjectObject } from '@/types/project' | ||
import { Callback } from '@/types/utils' | ||
import { useEnv } from '../env' | ||
|
||
export const useLocalStorage: Callback<any> = () => { | ||
const set = (obj: ProjectObject, name: string) => { | ||
localStorage.setItem(useEnv().projectLocalStorage(), JSON.stringify(obj)) | ||
} | ||
|
||
const get = (name: string) => { | ||
return JSON.parse((localStorage as any).getItem(name)) | ||
} | ||
|
||
const setProject = (obj: ProjectObject) => { | ||
set(obj, useEnv().projectLocalStorage()) | ||
} | ||
|
||
const getProject = (): ProjectObject => { | ||
return get(useEnv().projectLocalStorage()) | ||
} | ||
|
||
return { set, get, setProject, getProject } | ||
} |