hippofish/packages/client/src/pages/timeline.vue

325 lines
7.2 KiB
Vue
Raw Normal View History

<template>
2023-04-08 02:01:42 +02:00
<MkStickyContainer>
<template #header>
<MkPageHeader
v-model:tab="src"
:actions="headerActions"
:tabs="headerTabs"
:display-my-avatar="true"
:class="{ isMobile: 'xytnxiau' }"
2022-08-16 09:00:36 +02:00
/>
2023-04-08 02:01:42 +02:00
</template>
<MkSpacer :content-max="800" :class="{ isMobile: 'upsvvhaz' }">
2023-04-08 02:01:42 +02:00
<div ref="rootEl" v-hotkey.global="keymap" class="cmuxhskf">
<XPostForm
v-if="defaultStore.reactiveState.showFixedPostForm.value"
2023-04-08 02:01:42 +02:00
class="post-form _block"
fixed
/>
<!-- <div v-if="!isMobile" class="tl _block">
2022-08-16 09:00:36 +02:00
<XTimeline
ref="tl"
:key="src"
class="tl"
:src="src"
:sound="true"
@queue="queueUpdated"
2022-08-16 04:18:54 +02:00
/>
</div> *v-else on next div* -->
2023-04-08 02:01:42 +02:00
<div class="tl _block">
2023-05-26 04:47:10 +02:00
<swiper
2023-05-26 23:02:17 +02:00
:round-lengths="true"
2023-05-26 04:47:10 +02:00
:touch-angle="25"
:threshold="10"
2023-09-02 01:27:33 +02:00
:centered-slides="true"
2023-04-08 02:01:42 +02:00
:modules="[Virtual]"
:space-between="20"
:virtual="true"
2023-06-26 21:47:05 +02:00
:allow-touch-move="
defaultStore.state.swipeOnMobile &&
(deviceKind !== 'desktop' ||
defaultStore.state.swipeOnDesktop)
"
2023-04-08 02:01:42 +02:00
@swiper="setSwiperRef"
@slide-change="onSlideChange"
2022-08-28 00:49:10 +02:00
>
2023-04-08 02:01:42 +02:00
<swiper-slide
v-for="index in timelines"
:key="index"
:virtual-index="index"
>
<XTimeline
2023-05-26 01:32:56 +02:00
v-if="index == timelines[swiperRef.activeIndex]"
2023-04-08 02:01:42 +02:00
ref="tl"
:key="src"
class="tl"
:src="src"
:sound="true"
/>
</swiper-slide>
</swiper>
</div>
2022-08-23 07:31:00 +02:00
</div>
2023-04-08 02:01:42 +02:00
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
2023-09-02 01:27:33 +02:00
import { computed, onMounted, ref } from "vue";
import { Virtual } from "swiper/modules";
2023-04-08 02:01:42 +02:00
import { Swiper, SwiperSlide } from "swiper/vue";
import XTutorial from "@/components/MkTutorialDialog.vue";
import XTimeline from "@/components/MkTimeline.vue";
import XPostForm from "@/components/MkPostForm.vue";
import * as os from "@/os";
import { defaultStore } from "@/store";
import { i18n } from "@/i18n";
import { instance } from "@/instance";
import { $i, isSignedIn, isModerator } from "@/reactiveAccount";
2023-04-08 02:01:42 +02:00
import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind";
import icon from "@/scripts/icon";
2023-04-08 02:01:42 +02:00
import "swiper/scss";
import "swiper/scss/virtual";
if (isSignedIn && defaultStore.reactiveState.tutorial.value !== -1) {
2023-04-08 02:01:42 +02:00
os.popup(XTutorial, {}, {}, "closed");
2022-11-09 08:51:59 +01:00
}
2022-08-16 04:18:54 +02:00
const isLocalTimelineAvailable =
(!instance.disableLocalTimeline &&
(isSignedIn || instance.enableGuestTimeline)) ||
isModerator;
const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn;
const isRecommendedTimelineAvailable =
!instance.disableRecommendedTimeline && isSignedIn;
2022-08-16 04:18:54 +02:00
const isGlobalTimelineAvailable =
(!instance.disableGlobalTimeline &&
(isSignedIn || instance.enableGuestTimeline)) ||
isModerator;
const keymap = {
2022-08-16 04:18:54 +02:00
t: focus,
};
2023-09-02 01:27:33 +02:00
const timelines = ["home"];
2022-09-06 03:42:01 +02:00
if (isLocalTimelineAvailable) {
2023-04-08 02:01:42 +02:00
timelines.push("local");
2022-09-06 03:42:01 +02:00
}
if (isLocalTimelineAvailable) {
2023-05-15 00:20:26 +02:00
timelines.push("social");
}
if (isRecommendedTimelineAvailable) {
timelines.push("recommended");
}
2022-09-06 03:42:01 +02:00
if (isGlobalTimelineAvailable) {
2023-04-08 02:01:42 +02:00
timelines.push("global");
2022-09-06 03:42:01 +02:00
}
const MOBILE_THRESHOLD = 500;
// デスクトップでウィンドウを狭くしたときモバイルUIが表示されて欲しいことはあるので deviceKind === 'desktop' の判定は行わない
2022-08-16 04:18:54 +02:00
const isMobile = ref(
2023-07-06 03:28:27 +02:00
deviceKind === "smartphone" || window.innerWidth <= MOBILE_THRESHOLD,
2022-08-16 04:18:54 +02:00
);
2023-04-08 02:01:42 +02:00
window.addEventListener("resize", () => {
2022-08-16 04:18:54 +02:00
isMobile.value =
2023-04-08 02:01:42 +02:00
deviceKind === "smartphone" || window.innerWidth <= MOBILE_THRESHOLD;
});
const tlComponent = ref<InstanceType<typeof XTimeline>>();
const rootEl = ref<HTMLElement>();
const src = computed({
2022-09-09 22:47:19 +02:00
get: () => defaultStore.reactiveState.tl.value.src,
2022-09-06 03:34:48 +02:00
set: (x) => {
saveSrc(x);
2022-09-06 03:42:01 +02:00
syncSlide(timelines.indexOf(x));
2022-09-06 03:34:48 +02:00
},
2022-08-16 04:18:54 +02:00
});
2023-06-06 02:15:17 +02:00
const lists = os.api("users/lists/list");
async function chooseList(ev: MouseEvent) {
await lists.then((res) => {
const items = [
{
type: "link" as const,
text: i18n.ts.manageLists,
icon: `${icon("ph-faders-horizontal")}`,
2023-06-06 02:15:17 +02:00
to: "/my/lists",
},
].concat(
res.map((list) => ({
type: "link" as const,
text: list.name,
icon: "",
to: `/timeline/list/${list.id}`,
2023-07-06 03:28:27 +02:00
})),
2023-06-06 02:15:17 +02:00
);
os.popupMenu(items, ev.currentTarget ?? ev.target);
});
}
2023-06-06 02:15:17 +02:00
const antennas = os.api("antennas/list");
async function chooseAntenna(ev: MouseEvent) {
await antennas.then((res) => {
const items = [
{
type: "link" as const,
indicate: false,
text: i18n.ts.manageAntennas,
icon: `${icon("ph-faders-horizontal")}`,
2023-06-06 02:15:17 +02:00
to: "/my/antennas",
},
].concat(
res.map((antenna) => ({
type: "link" as const,
text: antenna.name,
icon: "",
indicate: antenna.hasUnreadNote,
to: `/timeline/antenna/${antenna.id}`,
2023-07-06 03:28:27 +02:00
})),
2023-06-06 02:15:17 +02:00
);
os.popupMenu(items, ev.currentTarget ?? ev.target);
});
}
2022-08-16 04:18:54 +02:00
function saveSrc(
2023-07-06 03:28:27 +02:00
newSrc: "home" | "local" | "social" | "recommended" | "global",
2022-08-16 04:18:54 +02:00
): void {
2023-04-08 02:01:42 +02:00
defaultStore.set("tl", {
...defaultStore.state.tl,
src: newSrc,
});
}
function focus(): void {
tlComponent.value.focus();
}
const headerActions = computed(() => [
2022-08-16 04:18:54 +02:00
{
icon: `${icon("ph-list-bullets")}`,
2022-08-16 04:18:54 +02:00
title: i18n.ts.lists,
text: i18n.ts.lists,
2022-08-16 04:18:54 +02:00
iconOnly: true,
handler: chooseList,
},
{
icon: `${icon("ph-flying-saucer")}`,
2022-08-16 04:18:54 +02:00
title: i18n.ts.antennas,
2023-01-13 01:35:57 +01:00
text: i18n.ts.antennas,
2022-08-16 04:18:54 +02:00
iconOnly: true,
handler: chooseAntenna,
} /* **TODO: fix timetravel** {
icon: `${icon('ph-calendar-blank')}`,
2022-07-26 23:29:52 +02:00
title: i18n.ts.jumpToSpecifiedDate,
iconOnly: true,
2022-07-26 23:35:12 +02:00
handler: timetravel,
2023-09-02 01:27:33 +02:00
} */,
2022-08-16 04:18:54 +02:00
]);
const headerTabs = computed(() => [
{
2023-05-15 00:20:26 +02:00
key: "home",
title: i18n.ts._timelines.home,
icon: `${icon("ph-house")}`,
iconOnly: true,
},
2022-08-16 04:18:54 +02:00
...(isLocalTimelineAvailable
? [
2023-04-08 02:01:42 +02:00
{
key: "local",
title: i18n.ts._timelines.local,
icon: `${icon("ph-users")}`,
2023-04-08 02:01:42 +02:00
iconOnly: true,
},
2024-02-11 18:50:57 +01:00
]
2022-08-16 04:18:54 +02:00
: []),
...(isLocalTimelineAvailable
? [
2023-04-08 02:01:42 +02:00
{
key: "social",
title: i18n.ts._timelines.social,
icon: `${icon("ph-handshake")}`,
2023-04-08 02:01:42 +02:00
iconOnly: true,
},
2024-02-11 18:50:57 +01:00
]
: []),
...(isRecommendedTimelineAvailable
? [
2023-05-15 00:20:26 +02:00
{
key: "recommended",
title: i18n.ts._timelines.recommended,
icon: `${icon("ph-thumbs-up")}`,
2023-05-15 00:20:26 +02:00
iconOnly: true,
},
2024-02-11 18:50:57 +01:00
]
: []),
2022-08-16 04:18:54 +02:00
...(isGlobalTimelineAvailable
? [
2023-04-08 02:01:42 +02:00
{
key: "global",
title: i18n.ts._timelines.global,
icon: `${icon("ph-planet")}`,
2023-04-08 02:01:42 +02:00
iconOnly: true,
},
2024-02-11 18:50:57 +01:00
]
2022-08-16 04:18:54 +02:00
: []),
]);
2022-08-16 04:18:54 +02:00
definePageMetadata(
computed(() => ({
title: i18n.ts.timeline,
icon:
src.value === "local"
? "ph-users ph-lg"
: src.value === "social"
2024-02-11 18:50:57 +01:00
? "ph-handshake ph-lg"
: src.value === "recommended"
? "ph-thumbs-up ph-lg"
: src.value === "global"
? "ph-planet ph-lg"
: "ph-house ph-lg",
2023-07-06 03:28:27 +02:00
})),
2022-08-16 04:18:54 +02:00
);
2022-08-28 00:49:10 +02:00
2022-11-10 01:58:35 +01:00
let swiperRef: any = null;
2022-08-28 00:49:10 +02:00
function setSwiperRef(swiper) {
2022-08-28 00:49:10 +02:00
swiperRef = swiper;
syncSlide(timelines.indexOf(src.value));
}
2022-08-28 00:49:10 +02:00
function onSlideChange() {
2022-09-06 03:34:48 +02:00
saveSrc(timelines[swiperRef.activeIndex]);
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
2022-08-28 00:49:10 +02:00
2022-11-10 01:56:33 +01:00
onMounted(() => {
syncSlide(timelines.indexOf(swiperRef.activeIndex));
2022-11-10 01:58:35 +01:00
});
</script>
<style lang="scss" scoped>
.xytnxiau {
overflow-y: hidden;
position: absolute;
top: 0;
}
.upsvvhaz {
padding-top: 67px;
}
2020-12-29 03:33:21 +01:00
.cmuxhskf {
2022-08-23 08:23:19 +02:00
--swiper-theme-color: var(--accent);
> .tl {
2023-05-12 02:38:54 +02:00
background: none;
}
}
</style>