Skip to content

Commit

Permalink
feat: メインタイムラインのタブをカスタマイズ可能に(misskey-dev#8759)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyatea committed Jun 11, 2024
1 parent 9849aab commit 1848901
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 44 deletions.
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,10 @@ export interface Locale extends ILocale {
* アカウント設定
*/
"accountSettings": string;
/**
* タイムラインのヘッダー
*/
"timelineHeader": string;
/**
* プロモーション
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ dayOverDayChanges: "前日比"
appearance: "アピアランス"
clientSettings: "クライアント設定"
accountSettings: "アカウント設定"
timelineHeader: "タイムラインのヘッダー"
promotion: "プロモーション"
promote: "プロモート"
numberOfDays: "日数"
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/pages/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const menuDef = computed(() => [{
text: i18n.ts.navbar,
to: '/settings/navbar',
active: currentPage.value?.route.name === 'navbar',
}, {
icon: 'ti ti-layout-navbar',
text: i18n.ts.timelineHeader,
to: '/settings/timelineheader',
active: currentPage.value?.route.name === 'timelineHeader',
}, {
icon: 'ti ti-equal-double',
text: i18n.ts.statusbar,
Expand Down
149 changes: 149 additions & 0 deletions packages/frontend/src/pages/settings/timelineHeader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div class="_gaps_m">
<FormSlot>
<template #label>{{ i18n.ts.timelineHeader }}</template>
<MkContainer :showHeader="false">
<Sortable
v-model="items"
itemKey="id"
:animation="150"
:handle="'.' + $style.itemHandle"
@start="e => e.item.classList.add('active')"
@end="e => e.item.classList.remove('active')"
>
<template #item="{element,index}">
<div
v-if="element.type === '-' || timelineHeaderItemDef[element.type]"
:class="$style.item"
>
<button class="_button" :class="$style.itemHandle"><i class="ti ti-menu"></i></button>

<i class="ti-fw" :class="[$style.itemIcon, timelineHeaderItemDef[element.type]?.icon]"></i><span :class="$style.itemText">{{ timelineHeaderItemDef[element.type]?.title }}</span>
<button class="_button" :class="$style.itemRemove" @click="removeItem(index)"><i class="ti ti-x"></i></button>
</div>
</template>
</Sortable>
</MkContainer>
</FormSlot>
<div class="_buttons">
<MkButton @click="addItem"><i class="ti ti-plus"></i> {{ i18n.ts.addItem }}</MkButton>
<MkButton danger @click="reset"><i class="ti ti-reload"></i> {{ i18n.ts.default }}</MkButton>
<MkButton primary class="save" @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, defineAsyncComponent, ref, watch } from 'vue';
import MkRadios from '@/components/MkRadios.vue';
import MkButton from '@/components/MkButton.vue';
import FormSlot from '@/components/form/slot.vue';
import MkContainer from '@/components/MkContainer.vue';
import * as os from '@/os.js';
import { navbarItemDef } from '@/navbar.js';
import { defaultStore } from '@/store.js';
import { unisonReload } from '@/scripts/unison-reload.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { timelineHeaderItemDef } from '@/timelineHeader.js';
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
const items = ref(defaultStore.state.timelineTopBar.map(x => ({
id: Math.random().toString(),
type: x,
})));
async function reloadAsk() {
const { canceled } = await os.confirm({
type: 'info',
text: i18n.ts.reloadToApplySetting,
});
if (canceled) return;
unisonReload();
}
async function addItem() {
const menu = Object.keys(timelineHeaderItemDef).filter(k => !defaultStore.state.timelineTopBar.includes(k));
console.log(menu);
const { canceled, result: item } = await os.select({
title: i18n.ts.addItem,
items: [...menu.map(k => ({
value: k, text: timelineHeaderItemDef[k].title,
}))],
});
if (canceled) return;
items.value = [...items.value, {
id: Math.random().toString(),
type: item,
}];
}
function removeItem(index: number) {
items.value.splice(index, 1);
}
async function save() {
defaultStore.set('timelineTopBar', items.value.map(x => x.type));
await reloadAsk();
}
function reset() {
items.value = defaultStore.def.timelineTopBar.default.map(x => ({
id: Math.random().toString(),
type: x,
}));
}
definePageMetadata(() => ({
title: i18n.ts.navbar,
icon: 'ti ti-list',
}));
</script>
<style lang="scss" module>
.item {
position: relative;
display: block;
line-height: 2.85rem;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
color: var(--navFg);
}
.itemIcon {
position: relative;
width: 32px;
margin-right: 8px;
}
.itemText {
position: relative;
font-size: 0.9em;
}
.itemRemove {
position: absolute;
z-index: 10000;
width: 32px;
height: 32px;
color: #ff2a2a;
right: 8px;
opacity: 0.8;
}
.itemHandle {
cursor: move;
width: 32px;
height: 32px;
margin: 0 8px;
opacity: 0.5;
}
</style>
61 changes: 18 additions & 43 deletions packages/frontend/src/pages/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { deviceKind } from '@/scripts/device-kind.js';
import { deepMerge } from '@/scripts/merge.js';
import { MenuItem } from '@/types/menu.js';
import { miLocalStorage } from '@/local-storage.js';
import { timelineHeaderItemDef } from '@/timelineHeader.js';
provide('shouldOmitHeaderTitle', true);
Expand Down Expand Up @@ -277,49 +278,23 @@ const headerActions = computed(() => {
}
return tmp;
});
const headerTabs = computed(() => [...(defaultStore.reactiveState.pinnedUserLists.value.map(l => ({
key: 'list:' + l.id,
title: l.name,
icon: 'ti ti-star',
iconOnly: true,
}))), {
key: 'home',
title: i18n.ts._timelines.home,
icon: 'ti ti-home',
iconOnly: true,
}, ...(isLocalTimelineAvailable ? [{
key: 'local',
title: i18n.ts._timelines.local,
icon: 'ti ti-planet',
iconOnly: true,
}, {
key: 'social',
title: i18n.ts._timelines.social,
icon: 'ti ti-universe',
iconOnly: true,
}] : []), ...(isGlobalTimelineAvailable ? [{
key: 'global',
title: i18n.ts._timelines.global,
icon: 'ti ti-whirl',
iconOnly: true,
}] : []), {
icon: 'ti ti-list',
title: i18n.ts.lists,
iconOnly: true,
onClick: chooseList,
}, {
icon: 'ti ti-antenna',
title: i18n.ts.antennas,
iconOnly: true,
onClick: chooseAntenna,
}, {
icon: 'ti ti-device-tv',
title: i18n.ts.channel,
iconOnly: true,
onClick: chooseChannel,
}] as Tab[]);
let headerTabs = computed(() => defaultStore.reactiveState.timelineTopBar.value.map(tab => ({
...(tab !== 'lists' && tab !== 'antennas' && tab !== 'channels' ? {
key: tab,
} : {}),
title: timelineHeaderItemDef[tab].title,
icon: timelineHeaderItemDef[tab].icon,
iconOnly: timelineHeaderItemDef[tab].iconOnly,
...(tab === 'lists' ? {
onClick: (ev) => chooseList(ev),
} : {}),
...(tab === 'antennas' ? {
onClick: (ev) => chooseAntenna(ev),
} : {}),
...(tab === 'channels' ? {
onClick: (ev) => chooseChannel(ev),
} : {}),
})) as Tab[]);
const headerTabsWhenNotLogin = computed(() => [
...(isLocalTimelineAvailable ? [{
key: 'local',
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/router/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ const routes: RouteDef[] = [{
path: '/navbar',
name: 'navbar',
component: page(() => import('@/pages/settings/navbar.vue')),
}, {
path: '/timelineheader',
name: 'timelineHeader',
component: page(() => import('@/pages/settings/timelineHeader.vue')),
}, {
path: '/statusbar',
name: 'statusbar',
Expand Down
21 changes: 20 additions & 1 deletion packages/frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export type SoundStore = {

volume: number;
}

export const isLocalTimelineAvailable = ($i == null && instance.policies.ltlAvailable) || ($i != null && $i.policies.ltlAvailable);
export const isGlobalTimelineAvailable = ($i == null && instance.policies.gtlAvailable) || ($i != null && $i.policies.gtlAvailable);
export const postFormActions: PostFormAction[] = [];
export const userActions: UserAction[] = [];
export const noteActions: NoteAction[] = [];
Expand Down Expand Up @@ -148,6 +149,22 @@ export const defaultStore = markRaw(new Storage('base', {
'ui',
],
},
timelineTopBar: {
where: 'deviceAccount',
default: [
'home',
...(isLocalTimelineAvailable ? [
'local',
'social',
] : []),
...(isGlobalTimelineAvailable ? [
'global',
] : []),
'lists',
'antennas',
'channels',
],
},
visibility: {
where: 'deviceAccount',
default: 'public' as (typeof Misskey.noteVisibilities)[number],
Expand Down Expand Up @@ -522,6 +539,8 @@ interface Watcher {
*/
import lightTheme from '@/themes/l-light.json5';
import darkTheme from '@/themes/d-green-lime.json5';
import { $i } from '@/account.js';
import { instance } from '@/instance.js';

export class ColdDeviceStorage {
public static default = {
Expand Down
Loading

0 comments on commit 1848901

Please sign in to comment.