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

417 lines
8.9 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"
2022-08-16 09:00:36 +02:00
/>
2023-04-08 02:01:42 +02:00
</template>
<MkSpacer :content-max="800">
<div ref="rootEl" v-hotkey.global="keymap" class="cmuxhskf">
<XPostForm
v-if="$store.reactiveState.showFixedPostForm.value"
class="post-form _block"
fixed
/>
2022-08-16 09:00:36 +02:00
2023-04-08 02:01:42 +02:00
<div v-if="queue > 0" class="new">
2023-06-26 21:47:05 +02:00
<button
class="_buttonPrimary _shadow"
2023-06-25 23:07:01 +02:00
@click="top()"
:class="{ instant: !$store.state.animation }"
>
2023-04-08 02:01:42 +02:00
{{ i18n.ts.newNoteRecived }}
2023-06-25 23:07:01 +02:00
<i class="ph-arrow-up ph-bold"></i>
2023-04-08 02:01:42 +02:00
</button>
</div>
<!-- <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"
:centeredSlides="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"
@queue="queueUpdated"
/>
</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-04-08 02:01:42 +02:00
import { computed, watch, ref, onMounted } from "vue";
import { Virtual } from "swiper";
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 { scroll } from "@/scripts/scroll";
import * as os from "@/os";
import { defaultStore } from "@/store";
import { i18n } from "@/i18n";
import { instance } from "@/instance";
import { $i } from "@/account";
import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind";
import "swiper/scss";
import "swiper/scss/virtual";
2022-11-09 08:51:59 +01:00
if (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 ||
($i != null && ($i.isModerator || $i.isAdmin));
const isRecommendedTimelineAvailable = !instance.disableRecommendedTimeline;
2022-08-16 04:18:54 +02:00
const isGlobalTimelineAvailable =
!instance.disableGlobalTimeline ||
($i != null && ($i.isModerator || $i.isAdmin));
const keymap = {
2022-08-16 04:18:54 +02:00
t: focus,
};
2023-05-15 00:20:26 +02:00
let 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-04-08 02:01:42 +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>();
let queue = $ref(0);
2022-08-16 04:18:54 +02:00
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
});
2022-08-16 04:18:54 +02:00
watch($$(src), () => (queue = 0));
function queueUpdated(q: number): void {
queue = q;
}
function top(): void {
scroll(rootEl, { top: 0 });
}
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: "ph-faders-horizontal ph-bold ph-lg",
to: "/my/lists",
},
].concat(
res.map((list) => ({
type: "link" as const,
text: list.name,
icon: "",
to: `/timeline/list/${list.id}`,
}))
);
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: "ph-faders-horizontal ph-bold ph-lg",
to: "/my/antennas",
},
].concat(
res.map((antenna) => ({
type: "link" as const,
text: antenna.name,
icon: "",
indicate: antenna.hasUnreadNote,
to: `/timeline/antenna/${antenna.id}`,
}))
);
os.popupMenu(items, ev.currentTarget ?? ev.target);
});
}
2022-08-16 04:18:54 +02:00
function saveSrc(
2023-06-01 00:29:54 +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,
});
}
async function timetravel(): Promise<void> {
const { canceled, result: date } = await os.inputDate({
title: i18n.ts.date,
});
if (canceled) return;
tlComponent.timetravel(date);
}
function focus(): void {
tlComponent.focus();
}
2022-08-16 04:18:54 +02:00
const headerActions = $computed(() => [
{
2023-04-08 02:01:42 +02:00
icon: "ph-list-bullets ph-bold ph-lg",
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,
},
{
2023-04-08 02:01:42 +02:00
icon: "ph-flying-saucer ph-bold ph-lg",
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** {
2023-03-11 22:01:04 +01:00
icon: 'ph-calendar-blank ph-bold ph-lg',
2022-07-26 23:29:52 +02:00
title: i18n.ts.jumpToSpecifiedDate,
iconOnly: true,
2022-07-26 23:35:12 +02:00
handler: timetravel,
2022-08-16 04:18:54 +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,
2023-05-15 00:20:26 +02:00
icon: "ph-house ph-bold ph-lg",
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: "ph-users ph-bold ph-lg",
iconOnly: true,
},
]
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: "ph-handshake ph-bold ph-lg",
2023-04-08 02:01:42 +02:00
iconOnly: true,
},
]
: []),
...(isRecommendedTimelineAvailable
? [
2023-05-15 00:20:26 +02:00
{
key: "recommended",
title: i18n.ts._timelines.recommended,
icon: "ph-thumbs-up ph-bold ph-lg",
2023-05-15 00:20:26 +02:00
iconOnly: true,
},
]
: []),
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: "ph-planet ph-bold ph-lg",
iconOnly: true,
},
]
2022-08-16 04:18:54 +02:00
: []),
]);
2022-08-16 04:18:54 +02:00
definePageMetadata(
computed(() => ({
title: i18n.ts.timeline,
icon:
2023-05-15 00:20:26 +02:00
src === "local"
? "ph-users ph-bold ph-lg"
: src === "social"
? "ph-handshake ph-bold ph-lg"
: src === "recommended"
? "ph-thumbs-up ph-bold ph-lg"
: src === "global"
? "ph-planet ph-bold ph-lg"
: "ph-house ph-bold ph-lg",
}))
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;
2022-09-09 22:56:42 +02:00
syncSlide(timelines.indexOf(src));
}
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>
2023-06-25 23:07:01 +02:00
@keyframes slideUp {
to {
transform: translateY(-100%);
opacity: 0;
}
}
2020-12-29 03:33:21 +01:00
.cmuxhskf {
2022-08-23 08:23:19 +02:00
--swiper-theme-color: var(--accent);
2020-02-18 20:08:35 +01:00
> .new {
2021-04-15 10:36:09 +02:00
position: sticky;
2023-06-25 23:07:01 +02:00
display: flex;
justify-content: center;
top: calc(var(--stickyTop, 0px) - 60px);
2020-02-18 20:08:35 +01:00
z-index: 1000;
2023-06-25 23:07:01 +02:00
width: 600px;
max-width: 100%;
2023-06-25 23:07:01 +02:00
height: 60px;
margin-top: -60px;
pointer-events: none;
2023-06-25 23:07:01 +02:00
margin-inline: auto;
z-index: 1001;
2023-06-25 23:07:01 +02:00
box-shadow: 0 24px 24px -20px var(--accentedBg);
&::after {
content: "";
position: absolute;
inset: 0;
border: 2px solid var(--accentDarken);
2023-06-26 21:47:05 +02:00
mask: linear-gradient(
to right,
transparent,
black 40% 60%,
transparent
);
-webkit-mask: linear-gradient(
to right,
transparent,
black 40% 60%,
transparent
);
2023-06-25 23:07:01 +02:00
}
2020-02-18 20:08:35 +01:00
> button {
2023-06-25 23:07:01 +02:00
display: flex;
position: absolute;
top: 120%;
margin-inline: auto;
border-radius: 2em;
2023-06-26 21:47:05 +02:00
padding: 0.5em 1.2em;
2023-06-25 23:07:01 +02:00
background: var(--accentedBg);
border: 0;
color: var(--accent);
overflow: hidden;
pointer-events: all;
2023-06-25 23:07:01 +02:00
transform: translateY(-100%);
opacity: 0;
2023-06-26 21:47:05 +02:00
animation: reset 0.4s forwards cubic-bezier(0, 0.4, 0, 1.1),
slideUp 1s 5s forwards cubic-bezier(1, 0, 1, 1);
2023-06-25 23:07:01 +02:00
&::before {
content: "";
position: absolute;
inset: 0;
background: var(--bg);
z-index: -1;
}
i {
2023-06-26 21:47:05 +02:00
margin-left: 0.7em;
2023-06-25 23:07:01 +02:00
border-left: 1px solid var(--accentedBg);
2023-06-26 21:47:05 +02:00
padding-left: 0.4em;
2023-06-25 23:07:01 +02:00
}
2020-02-18 20:08:35 +01:00
}
}
2021-10-14 11:51:15 +02:00
> .post-form {
border-radius: var(--radius);
}
> .tl {
2023-05-12 02:38:54 +02:00
background: none;
border-radius: var(--radius);
}
}
</style>