Skip to content

Commit

Permalink
feat(editor): last edit time in popover
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 13, 2021
1 parent 2d77714 commit 8b130a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
21 changes: 11 additions & 10 deletions src/components/editor/entity/EditorEntityInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
const { t } = useI18n()
const emitter = useEmitter()
const entity = useEntity()
const format = useFormat()
const props = defineProps({
modelValue: String,
Expand Down Expand Up @@ -126,8 +127,8 @@
const content = {
type: 'page-break',
raw: '__PAGE_BREAK__',
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
type.value = 'paragraph'
Expand All @@ -144,8 +145,8 @@
const content = {
type: 'line-break',
raw: '__LINE_BREAK__',
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
type.value = 'paragraph'
Expand All @@ -171,8 +172,8 @@
const content = {
type: 'image',
raw: reader.result,
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
type.value = 'paragraph'
Expand All @@ -196,8 +197,8 @@
const content = {
type: type.value,
raw: props.modelValue,
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
type.value = 'paragraph'
Expand Down Expand Up @@ -226,8 +227,8 @@
const content = {
type: type.value,
raw: normalize,
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
store.commit('context/addInPageWithPaste', content)
Expand Down
14 changes: 10 additions & 4 deletions src/components/editor/entity/EditorEntityShowPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</svg>
</HeroIcon>
</template>
<p>{{ t('editor.aside.entity.up') }}</p>
<p>{{ t('editor.aside.props.entity.up') }}</p>
</EditorEntityShowSelect>
<EditorEntityShowSelect @click.prevent.stop="onDownEntity">
<template #icon>
Expand All @@ -166,7 +166,7 @@
</svg>
</HeroIcon>
</template>
<p>{{ t('editor.aside.entity.down') }}</p>
<p>{{ t('editor.aside.props.entity.down') }}</p>
</EditorEntityShowSelect>
<EditorEntityShowSelect @click.prevent.stop="onDeleteEntity">
<template #icon>
Expand All @@ -185,7 +185,7 @@
</svg>
</HeroIcon>
</template>
<p>{{ t('editor.aside.entity.delete') }}</p>
<p>{{ t('editor.aside.props.entity.delete') }}</p>
</EditorEntityShowSelect>
</section>
<HeroIcon class="wb-icon" @mouseenter.prevent.stop="onAdjustEntityWrapper">
Expand All @@ -201,21 +201,27 @@
</svg>
</HeroIcon>
</section>
<section class="absolute wb-icon right-14 bottom-0 pointer-events-none">
<p>{{ update }}</p>
</section>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import { reactive, computed } from 'vue'
import { useStore } from 'vuex'
import { useI18n } from 'vue-i18n'
import { useFormat } from '@/use/format'
const store = useStore()
const { t } = useI18n()
const format = useFormat()
const state = reactive({
new: false as boolean,
switcher: false as boolean,
adjust: false as boolean,
})
const update = computed(() => format.lastTime(props.entity.updatedAt))
const props = defineProps({
entity: Object as any,
Expand Down
13 changes: 11 additions & 2 deletions src/use/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format } from 'date-fns'
import { format, formatRelative, parse } from 'date-fns'
import { ptBR, enUS } from 'date-fns/locale'

export const useFormat = () => {
const simple = (date: Date): string => {
Expand All @@ -9,5 +10,13 @@ export const useFormat = () => {
return simple(new Date())
}

return { simple, actually }
const lastTime = (updatedAt: string) => {
const updatedDate = parse(updatedAt, 'yyyy-MM-dd HH:mm:ss', new Date())

return formatRelative(updatedDate, new Date(), {
locale: document.documentElement.lang === 'pt-BR' ? ptBR : enUS,
})
}

return { simple, actually, lastTime }
}

0 comments on commit 8b130a3

Please sign in to comment.