Skip to content
Merged
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
17 changes: 16 additions & 1 deletion playwright/e2e/offline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import { expect, mergeTests } from '@playwright/test'
import { test as createCollectivesTest } from '../support/fixtures/create-collectives.ts'
import { test as offlineTest } from '../support/fixtures/offline.ts'
import { test as pageListTest } from '../support/fixtures/pageList.ts'
import { test as pageSidebarTest } from '../support/fixtures/pageSidebar.ts'

const test = mergeTests(createCollectivesTest, offlineTest, pageSidebarTest)
const test = mergeTests(createCollectivesTest, offlineTest, pageListTest, pageSidebarTest)

// As we switch on and off the network
// we cannot run tests in parallel.
Expand Down Expand Up @@ -36,4 +37,18 @@ test.describe('Offline mode', () => {
await expect(versionsTab).toContainText('Offline')
await setOnline()
})

test('Shows offline state for page content and loads it when back online', async ({ page, user, collective, pageList, setOffline, setOnline }) => {
await collective.createPage({ title: 'Offline page', content: 'Some content', user, page })
// Open the collective again, so that the page list contains the new page
await collective.openCollective()

await setOffline()
await pageList.openPage('Offline page')
await expect(page.locator('.collectives-text-container')).toContainText('Offline')
await expect(collective.getReaderContent()).toBeHidden()

await setOnline()
await expect(collective.getReaderContent()).toContainText('Some content')
})
})
17 changes: 10 additions & 7 deletions playwright/support/fixtures/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ async function setClientOffline(client: CDPSession): Promise<void> {
}

/**
* setOffline will turn the network off for the rest of the test and then on again.
* setOffline turns the network off until setOnline turns it on again.
* Both use the same CDP session, as network emulation is applied per session.
*/
export const test = base.extend<OfflineFixture>({
setOffline: async ({ context, page }, use) => {
export const test = base.extend<OfflineFixture & { networkClient: CDPSession }>({
networkClient: async ({ context, page }, use) => {
const client = await context.newCDPSession(page)
await use(() => setClientOffline(client))
await use(client)
await setClientOnline(client)
},
setOnline: async ({ context, page }, use) => {
const client = await context.newCDPSession(page)
await use(() => setClientOnline(client))
setOffline: async ({ networkClient }, use) => {
await use(() => setClientOffline(networkClient))
},
setOnline: async ({ networkClient }, use) => {
await use(() => setClientOnline(networkClient))
},
})
7 changes: 6 additions & 1 deletion src/components/CollectivePrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@
<div v-for="page in pagesTreeWalk()" v-show="!loading" :key="page.id">
<PagePrint
:page
@failed="failedCount += 1"
@loading="waitingFor.push(page.id)"
@ready="ready(page.id)" />
</div>
</div>
</template>

<script>
import { t } from '@nextcloud/l10n'
import { showError } from '@nextcloud/dialogs'
import { n, t } from '@nextcloud/l10n'
import debounce from 'debounce'
import { mapActions, mapState } from 'pinia'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
Expand Down Expand Up @@ -181,6 +183,9 @@ export default {

allImagesLoaded() {
this.loading = false
if (this.failedCount) {
showError(n('collectives', 'Could not load the content of %n page', 'Could not load the content of %n pages', this.failedCount))
}
this.$nextTick(() => {
// Scroll back to the beginning of the document
document.getElementById('content-vue').scrollIntoView()
Expand Down
57 changes: 50 additions & 7 deletions src/components/Page/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@
v-show="!contentLoaded"
type="text"
class="page-content-skeleton" />
<template v-if="showContentError">
<OfflineContent v-if="!networkOnline" />
<NcEmptyContent
v-else
:name="t('collectives', 'Could not load page content')"
:description="t('collectives', 'Make sure you are online and can reach the server.')">
<template #icon>
<AlertCircleOutlineIcon />
</template>
</NcEmptyContent>
</template>
<div
v-show="contentLoaded && !showEditor"
v-show="contentLoaded && !showEditor && !showContentError"
ref="readerEl"
data-collectives-el="reader"
data-cy-collectives="reader" />
Expand All @@ -33,8 +44,12 @@ import { t } from '@nextcloud/l10n'
import { useElementSize } from '@vueuse/core'
import { mapActions, mapState } from 'pinia'
import { ref, watch } from 'vue'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline.vue'
import OfflineContent from '../PageSidebar/OfflineContent.vue'
import SkeletonLoading from '../SkeletonLoading.vue'
import { useEditor } from '../../composables/useEditor.ts'
import { useNetworkState } from '../../composables/useNetworkState.ts'
import { useReader } from '../../composables/useReader.ts'
import pageContentMixin from '../../mixins/pageContentMixin.js'
import { useCirclesStore } from '../../stores/circles.js'
Expand All @@ -47,6 +62,9 @@ export default {
name: 'TextEditor',

components: {
AlertCircleOutlineIcon,
NcEmptyContent,
OfflineContent,
SkeletonLoading,
},

Expand All @@ -67,10 +85,11 @@ export default {
watch(width, (value) => {
document.documentElement.style.setProperty('--text-container-width', value + 'px')
})
const davContent = ref('')
const davContent = ref(null)
const { contentLoaded, editor, editorContent, editorEl, pageContent, setupEditor } = useEditor(davContent)
const { pageInfoBarPage, reader, readerEl, setupReader } = useReader(pageContent)
return { contentLoaded, davContent, editor, editorContent, editorEl, pageContent, pageInfoBarPage, reader, readerEl, setupEditor, setupReader, textContainer, width }
const { networkOnline } = useNetworkState()
return { contentLoaded, davContent, editor, editorContent, editorEl, networkOnline, pageContent, pageInfoBarPage, reader, readerEl, setupEditor, setupReader, textContainer, width }
},

data() {
Expand All @@ -95,6 +114,14 @@ export default {
showEditor() {
return this.currentCollectiveCanEdit && !this.loading('editor') && this.isTextEdit
},

// Fetching the content failed and the editor didn't provide it either
showContentError() {
return !this.showEditor
&& !this.loading('pageContent')
&& this.davContent === null
&& !this.pageContent
},
},

watch: {
Expand All @@ -103,6 +130,13 @@ export default {
this.getPageContent()
}
},

networkOnline: function(value) {
// Retry if fetching the content failed, e.g. while offline
if (value && this.davContent === null) {
this.getPageContent()
}
},
},

beforeMount() {
Expand Down Expand Up @@ -183,8 +217,8 @@ export default {
if (!!this.currentCollective.pageMode
// for new pages
|| this.loading('newPageContent')
// or when page is empty
|| !this.davContent.trim()) {
// or when page is empty (not just failed to load)
|| this.davContent?.trim() === '') {
this.setTextEdit()
this.done('newPageContent')
}
Expand Down Expand Up @@ -216,7 +250,10 @@ export default {
return
}

const changed = this.editorContent && (this.editorContent !== this.davContent)
// Without content fetched via DAV there is nothing to compare against; Text saves edits itself
const changed = this.davContent !== null
&& this.editorContent
&& this.editorContent !== this.davContent
if (changed) {
// Save pending changes in editor
// TODO: detect missing connection and display warning
Expand All @@ -231,8 +268,14 @@ export default {
}
},

/**
* Fetch the page content, keep the previous content if that fails
*/
async getPageContent() {
this.davContent = await this.fetchPageContent(this.currentPageDavUrl)
const content = await this.fetchPageContent(this.currentPageDavUrl)
if (content !== null) {
this.davContent = content
Comment thread
mejo- marked this conversation as resolved.
Resolved
}
this.done('pageContent')
},
},
Expand Down
28 changes: 27 additions & 1 deletion src/components/PagePrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
{{ pageTitleString }}
</h2>
<div
v-show="!loadFailed"
ref="readerEl"
class="sheet-view"
data-collectives-el="reader"
data-cy-collectives="reader" />
<NcNoteCard
v-if="loadFailed"
type="error"
:text="t('collectives', 'Could not load the content of this page.')" />
</div>
</template>

<script>
import { t } from '@nextcloud/l10n'
import { mapState } from 'pinia'
import { ref } from 'vue'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import { useReader } from '../composables/useReader.ts'
import pageContentMixin from '../mixins/pageContentMixin.js'
import { useCollectivesStore } from '../stores/collectives.js'
Expand All @@ -30,6 +37,10 @@ import { usePagesStore } from '../stores/pages.js'
export default {
name: 'PagePrint',

components: {
NcNoteCard,
},

mixins: [
pageContentMixin,
],
Expand All @@ -42,6 +53,7 @@ export default {
},

emits: [
'failed',
'loading',
'ready',
],
Expand All @@ -52,6 +64,12 @@ export default {
return { content, reader, readerEl, setupReader }
},

data() {
return {
loadFailed: false,
}
},

computed: {
...mapState(useCollectivesStore, ['currentCollectiveTitle']),
...mapState(usePagesStore, ['pageDavUrl']),
Expand All @@ -72,8 +90,16 @@ export default {
},

methods: {
t,

async getPageContent() {
this.content = await this.fetchPageContent(this.pageDavUrl(this.page))
const content = await this.fetchPageContent(this.pageDavUrl(this.page))
if (content === null) {
this.loadFailed = true
this.$emit('failed')
return
}
this.content = content
},
},
}
Expand Down
25 changes: 23 additions & 2 deletions src/components/PageVersion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<NcButton
:title="t('collectives', 'Restore this version')"
:aria-label="t('collectives', 'Restore this version')"
:disabled="loadFailed"
class="titleform-button"
@click="onRestoreVersion">
<template #icon>
Expand All @@ -49,8 +50,15 @@
id="text-container"
:class="[isFullWidth ? 'full-width-view' : 'sheet-view']">
<SkeletonLoading v-show="!contentLoaded" class="page-content-skeleton" type="text" />
<NcEmptyContent
v-if="loadFailed"
:name="t('collectives', 'Could not load this version')">
<template #icon>
<AlertCircleOutlineIcon />
</template>
</NcEmptyContent>
<div
v-show="contentLoaded"
v-show="contentLoaded && !loadFailed"
ref="readerEl"
data-collectives-el="reader"
data-cy-collectives="reader" />
Expand All @@ -66,6 +74,8 @@ import { ref } from 'vue'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActions from '@nextcloud/vue/components/NcActions'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline.vue'
import DockRightIcon from 'vue-material-design-icons/DockRight.vue'
import EmoticonIcon from 'vue-material-design-icons/EmoticonOutline.vue'
import RestoreIcon from 'vue-material-design-icons/Restore.vue'
Expand All @@ -81,11 +91,13 @@ export default {
name: 'PageVersion',

components: {
AlertCircleOutlineIcon,
DockRightIcon,
EmoticonIcon,
NcActionButton,
NcActions,
NcButton,
NcEmptyContent,
PageTitle,
RestoreIcon,
SkeletonLoading,
Expand All @@ -102,6 +114,12 @@ export default {
return { content, isMobile, reader, readerEl, setupReader }
},

data() {
return {
loadFailed: false,
}
},

computed: {
...mapState(useRootStore, ['loading']),
...mapState(useVersionsStore, ['selectedVersion']),
Expand Down Expand Up @@ -131,6 +149,7 @@ export default {
watch: {
'selectedVersion.mtime': function() {
this.content = ''
this.loadFailed = false
this.getPageContent()
},
},
Expand Down Expand Up @@ -164,7 +183,9 @@ export default {

async getPageContent() {
this.load(`version-${this.currentPageId}-${this.selectedVersion.mtime}`)
this.content = await this.fetchPageContent(this.selectedVersion.url)
const content = await this.fetchPageContent(this.selectedVersion.url)
this.loadFailed = content === null
this.content = content ?? ''
this.done(`version-${this.currentPageId}-${this.selectedVersion.mtime}`)
},
},
Expand Down
7 changes: 3 additions & 4 deletions src/composables/useEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { useSearch } from './useSearch.ts'
/**
* Composable for setting up the editor and reader.
*
* @param davContent markdown content fetched via dav.
* @param davContent markdown content fetched via dav, `null` until fetched successfully.
*/
export function useEditor(davContent: Ref<string>) {
export function useEditor(davContent: Ref<string | null>) {
const editor = ref<TextEditorInstance | null>(null)
const editorEl = ref<HTMLElement | null>(null)
const editorContent = ref<string | null>(null)
Expand All @@ -34,7 +34,7 @@ export function useEditor(davContent: Ref<string>) {
const collectivesStore = useCollectivesStore()
const pagesStore = usePagesStore()

const pageContent = computed(() => editorContent.value?.trim() || davContent.value)
const pageContent = computed(() => editorContent.value?.trim() || davContent.value || '')
const showCurrentPageOutline = computed(() => {
return pagesStore.hasOutline(pagesStore.currentPageId)
})
Expand Down Expand Up @@ -140,7 +140,6 @@ export function useEditor(davContent: Ref<string>) {

return {
contentLoaded,
davContent,
editor,
editorEl,
editorContent,
Expand Down
Loading
Loading