-
Notifications
You must be signed in to change notification settings - Fork 156
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
self-built app banner #9696
Merged
Merged
self-built app banner #9696
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7a1fd4b
wip self-built app banner
grimmoc b7d3823
wip almost complete
grimmoc 398b155
complete, final tests pending
grimmoc e30dc3d
fixed URL generation, works!
grimmoc ac093c7
clean up
grimmoc 3329ff0
added changelog
grimmoc 338bb0e
fixed pnpm lock
grimmoc f186897
linting
grimmoc b8cac1d
fixed test
grimmoc 39b8f6f
changes per request in pr
grimmoc b782233
added tests, moved component to web pkg
grimmoc dc67414
minor cosmetic changes
grimmoc 9b6eb25
changes per request from PO
grimmoc e7f4a55
added custom translation hack
grimmoc e853e2b
fixed after rebase
grimmoc 0181544
removed console log
grimmoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Added app banner for mobile devices | ||
|
||
We've added an app banner at the top of the web view for mobile devices asking the user whether they want to continue working in the app. By dismissing it, it will not show again until a new session is started, e.g. by opening a new tab. | ||
|
||
https://github.com/owncloud/web/pull/9696 |
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,153 @@ | ||
<template> | ||
<portal to="app.app-banner"> | ||
<div class="app-banner hide-desktop" :hidden="isVisible === false"> | ||
<oc-button | ||
variation="brand" | ||
appearance="raw" | ||
class="app-banner-exit" | ||
aria-label="Close" | ||
@click="close" | ||
> | ||
<oc-icon name="close" size="small" /> | ||
</oc-button> | ||
<div | ||
class="app-banner-icon" | ||
:style="{ 'background-image': `url('${appBannerSettings.icon}')` }" | ||
></div> | ||
<div class="info-container"> | ||
<div> | ||
<div class="app-title">{{ appBannerSettings.title }}</div> | ||
<div class="app-publisher">{{ appBannerSettings.publisher }}</div> | ||
<div v-if="appBannerSettings.additionalInformation !== ''" class="app-additional-info"> | ||
{{ $gettext(appBannerSettings.additionalInformation) }} | ||
</div> | ||
</div> | ||
</div> | ||
<a | ||
:href="appUrl" | ||
target="_blank" | ||
class="app-banner-cta" | ||
rel="noopener" | ||
aria-label="{{ $gettext(appBannerSettings.ctaText) }}" | ||
>{{ $gettext(appBannerSettings.ctaText) }}</a | ||
> | ||
</div> | ||
</portal> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, ref, unref } from 'vue' | ||
import { useRouter, useStore } from 'web-pkg' | ||
import { buildUrl } from 'web-pkg/src/helpers/router' | ||
import { useSessionStorage } from '@vueuse/core' | ||
|
||
export default defineComponent({ | ||
components: {}, | ||
props: { | ||
fileId: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const appBannerWasClosed = useSessionStorage('app_banner_closed', null) | ||
const isVisible = ref<boolean>(unref(appBannerWasClosed) === null) | ||
const store = useStore() | ||
const router = useRouter() | ||
const appBannerSettings = unref(store.getters.configuration.currentTheme.appBanner) | ||
const appUrl = computed(() => { | ||
return buildUrl(router, `/f/${props.fileId}`) | ||
.toString() | ||
.replace('https', appBannerSettings.appScheme) | ||
grimmoc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
const close = () => { | ||
isVisible.value = false | ||
useSessionStorage('app_banner_closed', 1) | ||
} | ||
|
||
return { | ||
appUrl, | ||
close, | ||
isVisible, | ||
appBannerSettings | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.hide-desktop { | ||
@media (min-width: 768px) { | ||
display: none; | ||
} | ||
} | ||
|
||
.app-banner { | ||
overflow-x: hidden; | ||
width: 100%; | ||
height: 84px; | ||
background: #f3f3f3; | ||
font-family: Helvetica, sans, sans-serif; | ||
z-index: 5; | ||
} | ||
|
||
.info-container { | ||
position: absolute; | ||
top: 10px; | ||
left: 104px; | ||
display: flex; | ||
overflow-y: hidden; | ||
width: 60%; | ||
height: 64px; | ||
align-items: center; | ||
color: #000; | ||
} | ||
|
||
.app-banner-icon { | ||
position: absolute; | ||
top: 10px; | ||
left: 30px; | ||
width: 64px; | ||
height: 64px; | ||
border-radius: 15px; | ||
background-size: 64px 64px; | ||
} | ||
|
||
.app-banner-cta { | ||
position: absolute; | ||
top: 32px; | ||
right: 10px; | ||
z-index: 1; | ||
display: block; | ||
padding: 0 10px; | ||
min-width: 10%; | ||
border-radius: 5px; | ||
background: #f3f3f3; | ||
color: #1474fc; | ||
font-size: 18px; | ||
text-align: center; | ||
text-decoration: none; | ||
} | ||
|
||
.app-title { | ||
font-size: 14px; | ||
} | ||
|
||
.app-publisher, | ||
.app-additional-info { | ||
font-size: 12px; | ||
} | ||
|
||
.app-banner-exit { | ||
position: absolute; | ||
top: 34px; | ||
left: 9px; | ||
margin: 0; | ||
width: 12px; | ||
height: 12px; | ||
border: 0; | ||
text-align: center; | ||
display: inline; | ||
} | ||
</style> |
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,33 @@ | ||
import { Router } from 'vue-router' | ||
|
||
export const buildUrl = (router: Router, pathname) => { | ||
const base = document.querySelector('base') | ||
const isHistoryMode = !!base | ||
const baseUrl = new URL(window.location.href.split('#')[0]) | ||
baseUrl.search = '' | ||
|
||
if (isHistoryMode) { | ||
// in history mode we can't determine the base path, it must be provided by the document | ||
baseUrl.pathname = new URL(base.href).pathname | ||
} else { | ||
// in hash mode, auto-determine the base path by removing `/index.html` | ||
if (baseUrl.pathname.endsWith('/index.html')) { | ||
baseUrl.pathname = baseUrl.pathname.split('/').slice(0, -1).filter(Boolean).join('/') | ||
} | ||
} | ||
|
||
/** | ||
* build full url by either | ||
* - concatenating baseUrl and pathname (for unknown/non-router urls, e.g. `oidc-callback.html`) or | ||
* - resolving via router (for known routes) | ||
*/ | ||
if (/\.(html?)$/i.test(pathname)) { | ||
baseUrl.pathname = [...baseUrl.pathname.split('/'), ...pathname.split('/')] | ||
.filter(Boolean) | ||
.join('/') | ||
} else { | ||
baseUrl[isHistoryMode ? 'pathname' : 'hash'] = router.resolve(pathname).href | ||
} | ||
|
||
return baseUrl.href | ||
} |
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 @@ | ||
export * from './routeOptions' | ||
export * from './buildUrl' |
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,96 @@ | ||
import { | ||
createStore, | ||
defaultComponentMocks, | ||
defaultPlugins, | ||
defaultStoreMockOptions, | ||
shallowMount | ||
} from 'web-test-helpers' | ||
import AppBanner from 'web-pkg/src/components/AppBanner.vue' | ||
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router' | ||
import { useSessionStorage } from '@vueuse/core' | ||
import { ref } from 'vue' | ||
|
||
jest.mock('@vueuse/core') | ||
|
||
describe('AppBanner', () => { | ||
it('generates app url with correct app scheme', () => { | ||
const baseElement = document.createElement('base') | ||
baseElement.href = '/' | ||
document.getElementsByTagName('head')[0].appendChild(baseElement) | ||
delete window.location | ||
window.location = new URL('https://localhost') as any | ||
|
||
const { wrapper } = getWrapper({ | ||
fileId: '1337', | ||
appScheme: 'owncloud', | ||
sessionStorageReturnValue: null | ||
}) | ||
expect(wrapper.find('.app-banner-cta').attributes().href).toBe('owncloud://localhost/f/1337') | ||
}) | ||
it('does not show when banner was closed', () => { | ||
const { wrapper } = getWrapper({ | ||
fileId: '1337', | ||
appScheme: 'owncloud', | ||
sessionStorageReturnValue: '1' | ||
}) | ||
expect(wrapper.find('.app-banner').attributes().hidden).toBe('') | ||
}) | ||
|
||
it('shows when banner was not yet closed', () => { | ||
const { wrapper } = getWrapper({ | ||
fileId: '1337', | ||
appScheme: 'owncloud', | ||
sessionStorageReturnValue: null | ||
}) | ||
expect(wrapper.find('.app-banner').attributes().hidden).toBe(undefined) | ||
}) | ||
}) | ||
|
||
function getWrapper({ fileId, appScheme, sessionStorageReturnValue }) { | ||
const storeOptions = { | ||
...defaultStoreMockOptions | ||
} | ||
|
||
storeOptions.getters.configuration.mockReturnValue({ | ||
currentTheme: { | ||
appBanner: { | ||
title: 'ownCloud', | ||
publisher: 'ownCloud GmbH', | ||
additionalInformation: 'FREE', | ||
ctaText: 'VIEW', | ||
icon: 'themes/owncloud/assets/owncloud-app-icon.png', | ||
appScheme | ||
} | ||
} | ||
}) | ||
|
||
const router = createRouter({ | ||
routes: [ | ||
{ | ||
path: '/f', | ||
component: {} | ||
} | ||
], | ||
history: ('/' && createWebHistory('/')) || createWebHashHistory() | ||
}) | ||
|
||
jest.mocked(useSessionStorage).mockImplementation(() => { | ||
return ref<string>(sessionStorageReturnValue) | ||
}) | ||
|
||
const mocks = { ...defaultComponentMocks(), $router: router } | ||
const store = createStore(storeOptions) | ||
|
||
return { | ||
wrapper: shallowMount(AppBanner, { | ||
props: { | ||
fileId | ||
}, | ||
global: { | ||
plugins: [...defaultPlugins(), store], | ||
mocks, | ||
provide: mocks | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure if this should be always required, as a generic component this could be shown even if not public link / file context