Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export notes #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async function fetchOldNotes() {
return JSON.parse(file || '[]')
}


export default Vue.extend({
components: {
Edit3Icon,
Expand Down
79 changes: 79 additions & 0 deletions components/Dropdown-menu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div class="dropdown">
<span class="dropdown-title">
{{title}}
<chevron-down-icon size='0.8x'/>
</span>
<div class="dropdown-content">
<a href='#' v-for='item in items'
v-bind:key="item.text"
v-on:click='itemOnClick(item)'>
<span v-if="inter" >
{{$inter.formatMessage({ path: item.text })}}
</span>
<span v-else>
{{ item.text }}
</span>
</a>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
import { ChevronDownIcon } from 'vue-feather-icons'
export default Vue.extend({
props: {
title:{
type: String,
default:'ddMenu'
},
items:{
type: Array,
default:[]
},
inter:{
type: Boolean,
default: true
}
},
methods:{
itemOnClick: function(item) {
this.$parent[item.callback]()
}
},
components: {
ChevronDownIcon
}
});
</script>
<style scoped>
.dropdown {
position: relative;
display: inline-block;
border-style: solid;
border-width: 1px;
}

.dropdown-content {
display: none;
position: absolute;
background-color:var(--body-bg);
min-width: 130px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 4px 8px;
top: 25px;
z-index: 1;
}
.dropdown-content > a{
Text-decoration: none;
}
.dropdown-title{
margin:5px;
}

.dropdown:hover .dropdown-content {
display: block;
}
</style>

51 changes: 46 additions & 5 deletions components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
</div>
</div>
<div class="header-right">
<span v-if="isSignedIn" class="nav-item" @click="signOut">
{{ $inter.formatMessage({ path: 'app.signOut' }) }}
</span>
<ddMenu v-if="isSignedIn"
:title=" $inter.formatMessage({ path: 'app.profile' })"
:items="items"
/>
<span v-else class="nav-item" @click="signIn">
{{ $inter.formatMessage({ path: 'app.signIn' }) }}
</span>
Expand All @@ -22,12 +23,29 @@
<script lang="ts">
import Vue from 'vue'
import { userSession } from '../utils/userSession'
import { NOTES_FILE } from '../utils/constants'
import Logo from './Logo.vue'
import ddMenu from './Dropdown-menu';

export default Vue.extend({
components: {
Logo
Logo,
ddMenu
},
data: ()=> {
return {
items: [
{
text:'app.exportNotes',
callback:'exportNotes'
},
{
text:'app.signOut',
callback:'signOut'
},
]
}
},

computed: {
isSignedIn() {
Expand All @@ -42,6 +60,28 @@ export default Vue.extend({

signOut() {
userSession.signUserOut('/')
},

exportNotes() {
userSession.getFile(NOTES_FILE).then(file=>{
if(file==="undefined"){
file = JSON.stringify({"notes":[],"updatedAt":Date.now()});
}
this.returnDownload(NOTES_FILE,file);
});
},

returnDownload(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);

element.style.display = 'none';
document.body.appendChild(element);

element.click();

document.body.removeChild(element);
}
}
})
Expand Down Expand Up @@ -77,4 +117,5 @@ export default Vue.extend({
.nav-item {
cursor: pointer;
}
</style>
</style>

4 changes: 4 additions & 0 deletions plugins/vue-inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const messages = {
signOut: 'Sign out',
signIn: 'Sign In',
slogan: 'A Decentralized Note-Taking App',
exportNotes: 'Export notes',
profile: 'Profile',
features() {
return [
{
Expand Down Expand Up @@ -55,6 +57,8 @@ const messages = {
signOut: '登出',
signIn: '登录',
slogan: '一个去中心化的笔记应用',
exportNotes: 'Export notes',
profile: 'Profile',
features() {
return [
{
Expand Down