feat: timeline page for non-login users (#9795)

This commit is contained in:
futchitwo 2023-02-05 14:02:54 +09:00 committed by GitHub
parent 505ecf6c1f
commit 04f92bd688
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 33 deletions

View file

@ -1,9 +1,9 @@
<template> <template>
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader v-model:tab="src" :actions="headerActions" :tabs="headerTabs" :display-my-avatar="true"/></template> <template #header><MkPageHeader v-model:tab="src" :actions="headerActions" :tabs="$i ? headerTabs : headerTabsWhenNotLogin" :display-my-avatar="true"/></template>
<MkSpacer :content-max="800"> <MkSpacer :content-max="800">
<div ref="rootEl" v-hotkey.global="keymap"> <div ref="rootEl" v-hotkey.global="keymap">
<XTutorial v-if="$store.reactiveState.tutorial.value != -1" class="_panel" style="margin-bottom: var(--margin);"/> <XTutorial v-if="$i && $store.reactiveState.tutorial.value != -1" class="_panel" style="margin-bottom: var(--margin);"/>
<XPostForm v-if="$store.reactiveState.showFixedPostForm.value" :class="$style.postForm" class="post-form _panel" fixed style="margin-bottom: var(--margin);"/> <XPostForm v-if="$store.reactiveState.showFixedPostForm.value" :class="$style.postForm" class="post-form _panel" fixed style="margin-bottom: var(--margin);"/>
<div v-if="queue > 0" :class="$style.new"><button class="_buttonPrimary" @click="top()">{{ i18n.ts.newNoteRecived }}</button></div> <div v-if="queue > 0" :class="$style.new"><button class="_buttonPrimary" @click="top()">{{ i18n.ts.newNoteRecived }}</button></div>
@ -45,7 +45,8 @@ const tlComponent = $shallowRef<InstanceType<typeof XTimeline>>();
const rootEl = $shallowRef<HTMLElement>(); const rootEl = $shallowRef<HTMLElement>();
let queue = $ref(0); let queue = $ref(0);
const src = $computed({ get: () => defaultStore.reactiveState.tl.value.src, set: (x) => saveSrc(x) }); let srcWhenNotSignin = $ref(isLocalTimelineAvailable ? 'local' : 'global');
const src = $computed({ get: () => ($i ? defaultStore.reactiveState.tl.value.src : srcWhenNotSignin), set: (x) => saveSrc(x) });
watch ($$(src), () => queue = 0); watch ($$(src), () => queue = 0);
@ -94,6 +95,7 @@ function saveSrc(newSrc: 'home' | 'local' | 'social' | 'global'): void {
...defaultStore.state.tl, ...defaultStore.state.tl,
src: newSrc, src: newSrc,
}); });
srcWhenNotSignin = newSrc;
} }
async function timetravel(): Promise<void> { async function timetravel(): Promise<void> {
@ -148,6 +150,21 @@ const headerTabs = $computed(() => [{
onClick: chooseChannel, onClick: chooseChannel,
}]); }]);
const headerTabsWhenNotLogin = $computed(() => [
...(isLocalTimelineAvailable ? [{
key: 'local',
title: i18n.ts._timelines.local,
icon: 'ti ti-planet',
iconOnly: true,
}] : []),
...(isGlobalTimelineAvailable ? [{
key: 'global',
title: i18n.ts._timelines.global,
icon: 'ti ti-whirl',
iconOnly: true,
}] : []),
]);
definePageMetadata(computed(() => ({ definePageMetadata(computed(() => ({
title: i18n.ts.timeline, title: i18n.ts.timeline,
icon: src === 'local' ? 'ti ti-planet' : src === 'social' ? 'ti ti-rocket' : src === 'global' ? 'ti ti-whirl' : 'ti ti-home', icon: src === 'local' ? 'ti ti-planet' : src === 'social' ? 'ti ti-rocket' : src === 'global' ? 'ti ti-whirl' : 'ti ti-home',

View file

@ -484,6 +484,9 @@ export const routes = [{
path: '/clicker', path: '/clicker',
component: page(() => import('./pages/clicker.vue')), component: page(() => import('./pages/clicker.vue')),
loginRequired: true, loginRequired: true,
}, {
path: '/timeline',
component: page(() => import('./pages/timeline.vue')),
}, { }, {
name: 'index', name: 'index',
path: '/', path: '/',

View file

@ -5,14 +5,14 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, defineAsyncComponent } from 'vue'; import { defineComponent, defineAsyncComponent } from 'vue';
import DesignA from './visitor/a.vue'; //import DesignA from './visitor/a.vue';
import DesignB from './visitor/b.vue'; import DesignB from './visitor/b.vue';
import XCommon from './_common_/common.vue'; import XCommon from './_common_/common.vue';
export default defineComponent({ export default defineComponent({
components: { components: {
XCommon, XCommon,
DesignA, //DesignA,
DesignB, DesignB,
}, },
}); });

View file

@ -10,7 +10,7 @@
<XKanban v-if="narrow && !root" class="banner" :powered-by="root"/> <XKanban v-if="narrow && !root" class="banner" :powered-by="root"/>
<div class="contents"> <div class="contents">
<XHeader v-if="!root" class="header" :info="pageInfo"/> <XHeader v-if="!root" class="header"/>
<main style="container-type: inline-size;"> <main style="container-type: inline-size;">
<RouterView/> <RouterView/>
</main> </main>
@ -33,9 +33,14 @@
<Transition :name="$store.state.animation ? 'tray' : ''"> <Transition :name="$store.state.animation ? 'tray' : ''">
<div v-if="showMenu" class="menu"> <div v-if="showMenu" class="menu">
<MkA to="/" class="link" active-class="active"><i class="ti ti-home icon"></i>{{ $ts.home }}</MkA> <MkA to="/" class="link" active-class="active"><i class="ti ti-home icon"></i>{{ $ts.home }}</MkA>
<MkA v-if="isTimelineAvailable" to="/timeline" class="link" active-class="active"><i class="ti ti-message icon"></i>{{ $ts.timeline }}</MkA>
<MkA to="/explore" class="link" active-class="active"><i class="ti ti-hash icon"></i>{{ $ts.explore }}</MkA> <MkA to="/explore" class="link" active-class="active"><i class="ti ti-hash icon"></i>{{ $ts.explore }}</MkA>
<MkA to="/featured" class="link" active-class="active"><i class="ti ti-flare icon"></i>{{ $ts.featured }}</MkA> <MkA to="/announcements" class="link" active-class="active"><i class="ti ti-speakerphone icon"></i>{{ $ts.announcements }}</MkA>
<MkA to="/channels" class="link" active-class="active"><i class="ti ti-device-tv icon"></i>{{ $ts.channel }}</MkA> <MkA to="/channels" class="link" active-class="active"><i class="ti ti-device-tv icon"></i>{{ $ts.channel }}</MkA>
<div class="divider"></div>
<MkA to="/pages" class="link" active-class="active"><i class="ti ti-news icon"></i>{{ $ts.pages }}</MkA>
<MkA to="/play" class="link" active-class="active"><i class="ti ti-player-play icon"></i>Play</MkA>
<MkA to="/gallery" class="link" active-class="active"><i class="ti ti-icons icon"></i>{{ $ts.gallery }}</MkA>
<div class="action"> <div class="action">
<button class="_buttonPrimary" @click="signup()">{{ $ts.signup }}</button> <button class="_buttonPrimary" @click="signup()">{{ $ts.signup }}</button>
<button class="_button" @click="signin()">{{ $ts.login }}</button> <button class="_button" @click="signin()">{{ $ts.login }}</button>
@ -52,6 +57,7 @@ import XKanban from './kanban.vue';
import { host, instanceName } from '@/config'; import { host, instanceName } from '@/config';
import { search } from '@/scripts/search'; import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import { instance } from '@/instance';
import MkPagination from '@/components/MkPagination.vue'; import MkPagination from '@/components/MkPagination.vue';
import XSigninDialog from '@/components/MkSigninDialog.vue'; import XSigninDialog from '@/components/MkSigninDialog.vue';
import XSignupDialog from '@/components/MkSignupDialog.vue'; import XSignupDialog from '@/components/MkSignupDialog.vue';
@ -76,6 +82,9 @@ const announcements = {
endpoint: 'announcements', endpoint: 'announcements',
limit: 10, limit: 10,
}; };
const isTimelineAvailable = instance.policies.ltlAvailable || instance.policies.gtlAvailable;
let showMenu = $ref(false); let showMenu = $ref(false);
let isDesktop = $ref(window.innerWidth >= DESKTOP_THRESHOLD); let isDesktop = $ref(window.innerWidth >= DESKTOP_THRESHOLD);
let narrow = $ref(window.innerWidth < 1280); let narrow = $ref(window.innerWidth < 1280);
@ -223,6 +232,12 @@ defineExpose({
} }
} }
> .divider {
margin: 8px auto;
width: calc(100% - 32px);
border-top: solid 0.5px var(--divider);
}
> .action { > .action {
padding: 16px; padding: 16px;

View file

@ -3,18 +3,9 @@
<div v-if="narrow === false" class="wide"> <div v-if="narrow === false" class="wide">
<div class="content"> <div class="content">
<MkA to="/" class="link" active-class="active"><i class="ti ti-home icon"></i>{{ $ts.home }}</MkA> <MkA to="/" class="link" active-class="active"><i class="ti ti-home icon"></i>{{ $ts.home }}</MkA>
<MkA v-if="isTimelineAvailable" to="/timeline" class="link" active-class="active"><i class="ti ti-message icon"></i>{{ $ts.timeline }}</MkA>
<MkA to="/explore" class="link" active-class="active"><i class="ti ti-hash icon"></i>{{ $ts.explore }}</MkA> <MkA to="/explore" class="link" active-class="active"><i class="ti ti-hash icon"></i>{{ $ts.explore }}</MkA>
<MkA to="/featured" class="link" active-class="active"><i class="ti ti-flare icon"></i>{{ $ts.featured }}</MkA>
<MkA to="/channels" class="link" active-class="active"><i class="ti ti-device-tv icon"></i>{{ $ts.channel }}</MkA> <MkA to="/channels" class="link" active-class="active"><i class="ti ti-device-tv icon"></i>{{ $ts.channel }}</MkA>
<div v-if="info" class="page active link">
<div class="title">
<i v-if="info.icon" class="icon" :class="info.icon"></i>
<MkAvatar v-else-if="info.avatar" class="avatar" :user="info.avatar" indicator/>
<span v-if="info.title" class="text">{{ info.title }}</span>
<MkUserName v-else-if="info.userName" :user="info.userName" :nowrap="false" class="text"/>
</div>
<button v-if="info.action" class="_button action" @click.stop="info.action.handler"><!-- TODO --></button>
</div>
<div class="right"> <div class="right">
<button class="_button search" @click="search()"><i class="ti ti-search icon"></i><span>{{ $ts.search }}</span></button> <button class="_button search" @click="search()"><i class="ti ti-search icon"></i><span>{{ $ts.search }}</span></button>
<button class="_buttonPrimary signup" @click="signup()">{{ $ts.signup }}</button> <button class="_buttonPrimary signup" @click="signup()">{{ $ts.signup }}</button>
@ -26,15 +17,6 @@
<button class="menu _button" @click="$parent.showMenu = true"> <button class="menu _button" @click="$parent.showMenu = true">
<i class="ti ti-menu-2 icon"></i> <i class="ti ti-menu-2 icon"></i>
</button> </button>
<div v-if="info" class="title">
<i v-if="info.icon" class="icon" :class="info.icon"></i>
<MkAvatar v-else-if="info.avatar" class="avatar" :user="info.avatar" indicator/>
<span v-if="info.title" class="text">{{ info.title }}</span>
<MkUserName v-else-if="info.userName" :user="info.userName" :nowrap="false" class="text"/>
</div>
<button v-if="info && info.action" class="action _button" @click.stop="info.action.handler">
<!-- TODO -->
</button>
</div> </div>
</div> </div>
</template> </template>
@ -44,19 +26,15 @@ import { defineComponent } from 'vue';
import XSigninDialog from '@/components/MkSigninDialog.vue'; import XSigninDialog from '@/components/MkSigninDialog.vue';
import XSignupDialog from '@/components/MkSignupDialog.vue'; import XSignupDialog from '@/components/MkSignupDialog.vue';
import * as os from '@/os'; import * as os from '@/os';
import { instance } from '@/instance';
import { search } from '@/scripts/search'; import { search } from '@/scripts/search';
export default defineComponent({ export default defineComponent({
props: {
info: {
required: true,
},
},
data() { data() {
return { return {
narrow: null, narrow: null,
showMenu: false, showMenu: false,
isTimelineAvailable: instance.policies.ltlAvailable || instance.policies.gtlAvailable,
}; };
}, },
@ -84,8 +62,9 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
.sqxihjet { .sqxihjet {
$height: 60px; $height: 50px;
position: sticky; position: sticky;
width: 50px;
top: 0; top: 0;
left: 0; left: 0;
z-index: 1000; z-index: 1000;