iceshrimp/src/client/app/desktop/views/components/home.vue

368 lines
9.0 KiB
Vue
Raw Normal View History

2018-02-09 09:46:23 +09:00
<template>
2018-02-11 13:02:35 +09:00
<div class="mk-home" :data-customize="customize">
2018-02-09 13:11:30 +09:00
<div class="customize" v-if="customize">
2018-02-23 02:06:35 +09:00
<router-link to="/">%fa:check%完了</router-link>
2018-02-09 13:11:30 +09:00
<div>
<div class="adder">
<p>ウィジェットを追加:</p>
2018-02-11 13:02:35 +09:00
<select v-model="widgetAdderSelected">
2018-02-09 13:11:30 +09:00
<option value="profile">プロフィール</option>
<option value="calendar">カレンダー</option>
<option value="timemachine">カレンダー(タイムマシン)</option>
<option value="activity">アクティビティ</option>
2018-02-21 01:12:18 +09:00
<option value="rss">RSSリーダー</option>
2018-02-09 13:11:30 +09:00
<option value="trends">トレンド</option>
<option value="photo-stream">フォトストリーム</option>
<option value="slideshow">スライドショー</option>
<option value="version">バージョン</option>
<option value="broadcast">ブロードキャスト</option>
<option value="notifications">通知</option>
2018-02-21 01:12:18 +09:00
<option value="users">おすすめユーザー</option>
<option value="polls">投票</option>
2018-02-09 13:11:30 +09:00
<option value="post-form">投稿フォーム</option>
<option value="messaging">メッセージ</option>
<option value="channel">チャンネル</option>
<option value="access-log">アクセスログ</option>
<option value="server">サーバー情報</option>
<option value="donation">寄付のお願い</option>
<option value="nav">ナビゲーション</option>
<option value="tips">ヒント</option>
</select>
<button @click="addWidget">追加</button>
</div>
<div class="trash">
2018-02-22 00:07:37 +09:00
<x-draggable v-model="trash" :options="{ group: 'x' }" @add="onTrash"></x-draggable>
2018-02-09 13:11:30 +09:00
<p>ゴミ箱</p>
</div>
</div>
</div>
<div class="main">
2018-02-22 00:07:37 +09:00
<template v-if="customize">
<x-draggable v-for="place in ['left', 'right']"
:list="widgets[place]"
:class="place"
:data-place="place"
:options="{ group: 'x', animation: 150 }"
@sort="onWidgetSort"
:key="place"
>
<div v-for="widget in widgets[place]" class="customize-container" :key="widget.id" @contextmenu.stop.prevent="onWidgetContextmenu(widget.id)">
2018-02-25 22:50:26 +09:00
<component :is="`mkw-${widget.name}`" :widget="widget" :ref="widget.id" :is-customize-mode="true"/>
2018-02-22 00:07:37 +09:00
</div>
</x-draggable>
<div class="main">
2018-02-23 02:06:35 +09:00
<a @click="hint">カスタマイズのヒント</a>
<div>
2018-04-08 03:58:11 +09:00
<mk-post-form v-if="os.i.clientSettings.showPostFormOnTopOfTl"/>
2018-02-23 02:06:35 +09:00
<mk-timeline ref="tl" @loaded="onTlLoaded"/>
</div>
2018-02-22 00:07:37 +09:00
</div>
</template>
<template v-else>
<div v-for="place in ['left', 'right']" :class="place">
2018-02-24 07:49:03 +09:00
<component v-for="widget in widgets[place]" :is="`mkw-${widget.name}`" :key="widget.id" :ref="widget.id" :widget="widget" @chosen="warp"/>
2018-02-22 00:07:37 +09:00
</div>
<div class="main">
2018-04-08 03:58:11 +09:00
<mk-post-form v-if="os.i.clientSettings.showPostFormOnTopOfTl"/>
2018-02-22 00:07:37 +09:00
<mk-timeline ref="tl" @loaded="onTlLoaded" v-if="mode == 'timeline'"/>
<mk-mentions @loaded="onTlLoaded" v-if="mode == 'mentions'"/>
</div>
</template>
2018-02-09 09:46:23 +09:00
</div>
2018-02-09 13:11:30 +09:00
</div>
2018-02-09 09:46:23 +09:00
</template>
2018-02-11 13:09:46 +09:00
<script lang="ts">
2018-02-11 13:02:35 +09:00
import Vue from 'vue';
2018-02-22 00:07:37 +09:00
import * as XDraggable from 'vuedraggable';
2018-02-11 13:09:46 +09:00
import * as uuid from 'uuid';
2018-02-09 13:11:30 +09:00
2018-02-11 13:02:35 +09:00
export default Vue.extend({
2018-02-22 00:07:37 +09:00
components: {
XDraggable
},
2018-02-09 13:11:30 +09:00
props: {
2018-04-08 03:58:11 +09:00
customize: {
type: Boolean,
default: false
},
2018-02-09 13:11:30 +09:00
mode: {
type: String,
default: 'timeline'
}
},
data() {
return {
2018-02-24 07:49:03 +09:00
connection: null,
connectionId: null,
2018-02-22 00:07:37 +09:00
widgetAdderSelected: null,
trash: [],
widgets: {
left: [],
right: []
}
2018-02-09 13:11:30 +09:00
};
},
2018-02-19 18:26:20 +09:00
computed: {
2018-02-22 00:07:37 +09:00
home: {
get(): any[] {
//#region 互換性のため
2018-04-08 03:58:11 +09:00
(this as any).os.i.clientSettings.home.forEach(w => {
2018-02-22 00:07:37 +09:00
if (w.name == 'rss-reader') w.name = 'rss';
if (w.name == 'user-recommendation') w.name = 'users';
if (w.name == 'recommended-polls') w.name = 'polls';
});
//#endregion
2018-04-08 03:58:11 +09:00
return (this as any).os.i.clientSettings.home;
2018-02-22 00:07:37 +09:00
},
set(value) {
2018-04-08 03:58:11 +09:00
(this as any).os.i.clientSettings.home = value;
2018-02-22 00:07:37 +09:00
}
2018-02-21 20:55:03 +09:00
},
2018-02-22 00:07:37 +09:00
left(): any[] {
2018-02-21 20:55:03 +09:00
return this.home.filter(w => w.place == 'left');
2018-02-19 18:26:20 +09:00
},
2018-02-22 00:07:37 +09:00
right(): any[] {
2018-02-21 20:55:03 +09:00
return this.home.filter(w => w.place == 'right');
2018-02-19 18:26:20 +09:00
}
},
2018-02-22 00:07:37 +09:00
created() {
this.widgets.left = this.left;
this.widgets.right = this.right;
2018-04-08 03:58:11 +09:00
this.$watch('os.i.clientSettings', i => {
2018-02-22 00:07:37 +09:00
this.widgets.left = this.left;
this.widgets.right = this.right;
}, {
deep: true
});
},
2018-02-24 07:49:03 +09:00
mounted() {
this.connection = (this as any).os.stream.getConnection();
this.connectionId = (this as any).os.stream.use();
this.connection.on('home_updated', this.onHomeUpdated);
},
beforeDestroy() {
this.connection.off('home_updated', this.onHomeUpdated);
(this as any).os.stream.dispose(this.connectionId);
},
2018-02-09 13:11:30 +09:00
methods: {
2018-02-23 02:06:35 +09:00
hint() {
(this as any).apis.dialog({
title: '%fa:info-circle%カスタマイズのヒント',
text: '<p>ホームのカスタマイズでは、ウィジェットを追加/削除したり、ドラッグ&ドロップして並べ替えたりすることができます。</p>' +
'<p>一部のウィジェットは、<strong><strong>右</strong>クリック</strong>することで表示を変更することができます。</p>' +
'<p>ウィジェットを削除するには、ヘッダーの<strong>「ゴミ箱」</strong>と書かれたエリアにウィジェットをドラッグ&ドロップします。</p>' +
'<p>カスタマイズを終了するには、右上の「完了」をクリックします。</p>',
actions: [{
text: 'Got it!'
}]
});
},
2018-02-09 13:11:30 +09:00
onTlLoaded() {
this.$emit('loaded');
},
2018-02-24 07:49:03 +09:00
onHomeUpdated(data) {
if (data.home) {
2018-04-08 03:58:11 +09:00
(this as any).os.i.clientSettings.home = data.home;
2018-02-24 07:49:03 +09:00
this.widgets.left = data.home.filter(w => w.place == 'left');
this.widgets.right = data.home.filter(w => w.place == 'right');
} else {
2018-04-08 03:58:11 +09:00
const w = (this as any).os.i.clientSettings.home.find(w => w.id == data.id);
2018-02-24 07:49:03 +09:00
if (w != null) {
w.data = data.data;
this.$refs[w.id][0].preventSave = true;
this.$refs[w.id][0].props = w.data;
2018-04-08 03:58:11 +09:00
this.widgets.left = (this as any).os.i.clientSettings.home.filter(w => w.place == 'left');
this.widgets.right = (this as any).os.i.clientSettings.home.filter(w => w.place == 'right');
2018-02-24 07:49:03 +09:00
}
}
},
2018-02-09 13:11:30 +09:00
onWidgetContextmenu(widgetId) {
2018-02-22 01:08:49 +09:00
const w = (this.$refs[widgetId] as any)[0];
if (w.func) w.func();
2018-02-09 13:11:30 +09:00
},
2018-02-22 00:07:37 +09:00
onWidgetSort() {
this.saveHome();
},
onTrash(evt) {
this.saveHome();
},
2018-02-09 13:11:30 +09:00
addWidget() {
const widget = {
2018-02-11 13:02:35 +09:00
name: this.widgetAdderSelected,
2018-02-09 13:11:30 +09:00
id: uuid(),
place: 'left',
data: {}
};
2018-02-22 00:07:37 +09:00
this.widgets.left.unshift(widget);
2018-02-09 13:11:30 +09:00
this.saveHome();
},
saveHome() {
2018-02-22 00:07:37 +09:00
const left = this.widgets.left;
const right = this.widgets.right;
this.home = left.concat(right);
left.forEach(w => w.place = 'left');
right.forEach(w => w.place = 'right');
2018-02-18 12:35:18 +09:00
(this as any).api('i/update_home', {
2018-02-21 15:30:03 +09:00
home: this.home
2018-02-11 13:02:35 +09:00
});
2018-02-09 13:11:30 +09:00
},
2018-02-19 18:26:20 +09:00
warp(date) {
2018-02-24 23:56:57 +09:00
(this.$refs.tl as any).warp(date);
2018-02-09 13:11:30 +09:00
}
}
2018-02-11 13:02:35 +09:00
});
2018-02-09 13:11:30 +09:00
</script>
2018-02-09 09:46:23 +09:00
<style lang="stylus" scoped>
2018-03-03 13:47:55 +09:00
@import '~const.styl'
2018-04-21 10:10:04 +09:00
root(isDark)
2018-02-11 13:02:35 +09:00
display block
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
&[data-customize]
padding-top 48px
background-image url('/assets/desktop/grid.svg')
2018-02-09 09:46:23 +09:00
2018-02-22 00:21:07 +09:00
> .main > .main
2018-02-23 02:06:35 +09:00
> a
display block
margin-bottom 8px
text-align center
2018-02-09 09:46:23 +09:00
2018-02-23 02:06:35 +09:00
> div
cursor not-allowed !important
> *
pointer-events none
2018-02-11 13:02:35 +09:00
&:not([data-customize])
> .main > *:empty
display none
> .customize
position fixed
z-index 1000
top 0
left 0
width 100%
height 48px
2018-04-21 10:10:04 +09:00
color isDark ? #fff : #000
background isDark ? #313543 : #f7f7f7
2018-02-11 13:02:35 +09:00
box-shadow 0 1px 1px rgba(0, 0, 0, 0.075)
> a
display block
position absolute
z-index 1001
top 0
right 0
padding 0 16px
line-height 48px
text-decoration none
color $theme-color-foreground
background $theme-color
transition background 0.1s ease
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
&:hover
background lighten($theme-color, 10%)
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
&:active
background darken($theme-color, 10%)
transition background 0s ease
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
> [data-fa]
margin-right 8px
> div
2018-02-09 09:46:23 +09:00
display flex
margin 0 auto
2018-02-11 13:02:35 +09:00
max-width 1200px - 32px
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
> div
width 50%
&.adder
> p
display inline
line-height 48px
&.trash
2018-04-21 10:10:04 +09:00
border-left solid 1px isDark ? #1c2023 : #ddd
2018-02-11 13:02:35 +09:00
> div
width 100%
height 100%
> p
position absolute
top 0
left 0
width 100%
line-height 48px
margin 0
text-align center
2018-02-09 09:46:23 +09:00
pointer-events none
2018-02-11 13:02:35 +09:00
> .main
display flex
justify-content center
margin 0 auto
max-width 1200px
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
> *
.customize-container
cursor move
2018-02-22 21:29:04 +09:00
border-radius 6px
&:hover
box-shadow 0 0 8px rgba(64, 120, 200, 0.3)
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
> *
pointer-events none
2018-02-09 09:46:23 +09:00
2018-02-19 18:26:20 +09:00
> .main
2018-02-11 13:02:35 +09:00
padding 16px
width calc(100% - 275px * 2)
2018-02-22 00:07:37 +09:00
order 2
2018-02-09 09:46:23 +09:00
2018-02-23 02:06:35 +09:00
.mk-post-form
margin-bottom 16px
2018-04-21 10:10:04 +09:00
border solid 1px rgba(#000, 0.075)
2018-02-23 02:06:35 +09:00
border-radius 4px
2018-02-22 22:03:44 +09:00
> *:not(.main)
2018-02-11 13:02:35 +09:00
width 275px
2018-02-19 18:26:20 +09:00
padding 16px 0 16px 0
2018-02-09 09:46:23 +09:00
2018-02-19 18:26:20 +09:00
> *:not(:last-child)
margin-bottom 16px
2018-02-09 09:46:23 +09:00
2018-02-11 13:02:35 +09:00
> .left
padding-left 16px
2018-02-22 00:07:37 +09:00
order 1
2018-02-11 13:02:35 +09:00
> .right
padding-right 16px
2018-02-22 00:07:37 +09:00
order 3
2018-02-11 13:02:35 +09:00
@media (max-width 1100px)
2018-02-22 22:03:44 +09:00
> *:not(.main)
2018-02-11 13:02:35 +09:00
display none
2018-02-19 18:26:20 +09:00
> .main
2018-02-11 13:02:35 +09:00
float none
width 100%
max-width 700px
margin 0 auto
2018-02-09 09:46:23 +09:00
2018-04-21 10:10:04 +09:00
.mk-home[data-darkmode]
root(true)
.mk-home:not([data-darkmode])
root(false)
2018-02-09 09:46:23 +09:00
</style>