WORK IN PROGRESS

This commit is contained in:
tamaina 2021-02-21 14:35:54 +09:00
parent b040c4da2f
commit 852e4db958
5 changed files with 21 additions and 17 deletions

View file

@ -17,6 +17,7 @@ const data = localStorage.getItem('account');
export const $i = data ? reactive(JSON.parse(data) as Account) : null; export const $i = data ? reactive(JSON.parse(data) as Account) : null;
export async function signout() { export async function signout() {
waiting();
localStorage.removeItem('account'); localStorage.removeItem('account');
//#region Remove account //#region Remove account
@ -42,7 +43,7 @@ export async function signout() {
document.cookie = `igi=; path=/`; document.cookie = `igi=; path=/`;
if (accounts.length > 0) login(accounts[0].token); if (accounts.length > 0) login(accounts[0].token);
else location.href = '/'; else unisonReload(true);
} }
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> { export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
@ -92,16 +93,16 @@ export function refreshAccount() {
return fetchAccount($i.token).then(updateAccount); return fetchAccount($i.token).then(updateAccount);
} }
export async function login(token: Account['token'], href?: string) { export async function login(token: Account['token'], redirect?: string) {
waiting(); waiting();
if (_DEV_) console.log('logging as token ', token); if (_DEV_) console.log('logging as token ', token);
const me = await fetchAccount(token); const me = await fetchAccount(token);
localStorage.setItem('account', JSON.stringify(me)); localStorage.setItem('account', JSON.stringify(me));
await addAccount(me.id, token); await addAccount(me.id, token);
if (href) { if (redirect) {
reloadChannel.postMessage('reload'); reloadChannel.postMessage('reload');
location.href = href; location.href = redirect;
return; return;
} }

View file

@ -115,14 +115,14 @@ export default defineComponent({
this.connection = os.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
//
// notification.isRead
this.connection.on('readAllNotifications', () => { this.connection.on('readAllNotifications', () => {
this.readObserver.unobserve(this.$el); this.readObserver.unobserve(this.$el);
this.notification = markNotificationRead(this.notification);
}); });
this.connection.on('readNotifications', notificationIds => { this.connection.on('readNotifications', notificationIds => {
if (notificationIds.includes(this.notification.id)) { if (notificationIds.includes(this.notification.id)) {
this.readObserver.unobserve(this.$el); this.readObserver.unobserve(this.$el);
this.notification = markNotificationRead(this.notification);
} }
}) })
} }

View file

@ -66,7 +66,7 @@ import { search } from '@/scripts/search';
import { isMobile } from '@/scripts/is-mobile'; import { isMobile } from '@/scripts/is-mobile';
import { getThemes } from '@/theme-store'; import { getThemes } from '@/theme-store';
import { initializeSw } from '@/scripts/initialize-sw'; import { initializeSw } from '@/scripts/initialize-sw';
import { reloadChannel } from '@/scripts/unison-reload'; import { reload, reloadChannel } from '@/scripts/unison-reload';
import { deleteLoginId } from '@/scripts/login-id'; import { deleteLoginId } from '@/scripts/login-id';
import { getAccountFromId } from '@/scripts/get-account-from-id'; import { getAccountFromId } from '@/scripts/get-account-from-id';
@ -120,7 +120,7 @@ if (defaultStore.state.reportError && !_DEV_) {
document.addEventListener('touchend', () => {}, { passive: true }); document.addEventListener('touchend', () => {}, { passive: true });
// 一斉リロード // 一斉リロード
reloadChannel.addEventListener('message', () => location.reload()); reloadChannel.addEventListener('message', reload);
//#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ //#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
// TODO: いつの日にか消したい // TODO: いつの日にか消したい

View file

@ -1,10 +1,18 @@
// SafariがBroadcastChannel未実装なのでライブラリを使う // SafariがBroadcastChannel未実装なのでライブラリを使う
import { BroadcastChannel } from 'broadcast-channel'; import { BroadcastChannel } from 'broadcast-channel';
export const reloadChannel = new BroadcastChannel<'reload'>('reload'); export const reloadChannel = new BroadcastChannel<boolean>('reload');
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。 // BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
export function unisonReload() { export function unisonReload(redirectToRoot?: boolean) {
reloadChannel.postMessage('reload'); reloadChannel.postMessage(!!redirectToRoot);
location.reload(); reload();
}
export function reload(redirectToRoot?: boolean) {
if (redirectToRoot) {
location.href = '/';
} else {
location.reload();
}
} }

View file

@ -5042,11 +5042,6 @@ idb-keyval@5.0.2:
resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.2.tgz#243cf2b7db1bee2a8a41b78c14a18a85db0e1646" resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.2.tgz#243cf2b7db1bee2a8a41b78c14a18a85db0e1646"
integrity sha512-1DYjY/nX2U9pkTkwFoAmKcK1ZWmkNgO32Oon9tp/9+HURizxUQ4fZRxMJZs093SldP7q6dotVj03kIkiqOILyA== integrity sha512-1DYjY/nX2U9pkTkwFoAmKcK1ZWmkNgO32Oon9tp/9+HURizxUQ4fZRxMJZs093SldP7q6dotVj03kIkiqOILyA==
idb-keyval@5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.1.tgz#d3913debfb58edee299da5cf2dded6c2670c05ef"
integrity sha512-bfi+Znn6oSPPgGcVUj2tYMIOQ5TD6V1qj50SdKQecGZx9lqUATcQ7ArHOt9sPcEhACoYe//yr2igmS6SMc59SA==
ieee754@1.1.13, ieee754@^1.1.13, ieee754@^1.1.4: ieee754@1.1.13, ieee754@^1.1.13, ieee754@^1.1.4:
version "1.1.13" version "1.1.13"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"