refactor: remove type errors from deck.vue and deck-store.ts
This commit is contained in:
parent
c51347d78b
commit
452a8ed930
|
|
@ -294,6 +294,21 @@ export function inputText(props: {
|
||||||
} | {
|
} | {
|
||||||
canceled: false; result: string;
|
canceled: false; result: string;
|
||||||
}>;
|
}>;
|
||||||
|
// min lengthが指定されてたら result は null になり得ないことを保証する overload function
|
||||||
|
export function inputText(props: {
|
||||||
|
type?: 'text' | 'email' | 'password' | 'url';
|
||||||
|
title?: string;
|
||||||
|
text?: string;
|
||||||
|
placeholder?: string | null;
|
||||||
|
autocomplete?: string;
|
||||||
|
default?: string;
|
||||||
|
minLength: number;
|
||||||
|
maxLength?: number;
|
||||||
|
}): Promise<{
|
||||||
|
canceled: true; result: undefined;
|
||||||
|
} | {
|
||||||
|
canceled: false; result: string;
|
||||||
|
}>;
|
||||||
export function inputText(props: {
|
export function inputText(props: {
|
||||||
type?: 'text' | 'email' | 'password' | 'url';
|
type?: 'text' | 'email' | 'password' | 'url';
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
:ref="id"
|
:ref="id"
|
||||||
:key="id"
|
:key="id"
|
||||||
:class="$style.column"
|
:class="$style.column"
|
||||||
:column="columns.find(c => c.id === id)"
|
:column="columns.find(c => c.id === id)!"
|
||||||
:isStacked="ids.length > 1"
|
:isStacked="ids.length > 1"
|
||||||
@headerWheel="onWheel"
|
@headerWheel="onWheel"
|
||||||
/>
|
/>
|
||||||
|
|
@ -185,7 +185,7 @@ const addColumn = async (ev) => {
|
||||||
'mentions',
|
'mentions',
|
||||||
'direct',
|
'direct',
|
||||||
'roleTimeline',
|
'roleTimeline',
|
||||||
];
|
] as const;
|
||||||
|
|
||||||
const { canceled, result: column } = await os.select({
|
const { canceled, result: column } = await os.select({
|
||||||
title: i18n.ts._deck.addColumn,
|
title: i18n.ts._deck.addColumn,
|
||||||
|
|
@ -194,6 +194,7 @@ const addColumn = async (ev) => {
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
if (canceled) return;
|
if (canceled) return;
|
||||||
|
if (column == null) return;
|
||||||
|
|
||||||
addColumnToStore({
|
addColumnToStore({
|
||||||
type: column,
|
type: column,
|
||||||
|
|
@ -212,7 +213,7 @@ const onContextmenu = (ev) => {
|
||||||
|
|
||||||
function onWheel(ev: WheelEvent) {
|
function onWheel(ev: WheelEvent) {
|
||||||
if (ev.deltaX === 0) {
|
if (ev.deltaX === 0) {
|
||||||
columnsEl.value.scrollLeft += ev.deltaY;
|
columnsEl.value!.scrollLeft += ev.deltaY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ type ColumnWidget = {
|
||||||
|
|
||||||
export type Column = {
|
export type Column = {
|
||||||
id: string;
|
id: string;
|
||||||
type: 'main' | 'widgets' | 'notifications' | 'tl' | 'antenna' | 'channel' | 'list' | 'mentions' | 'direct';
|
type: 'main' | 'widgets' | 'notifications' | 'tl' | 'antenna' | 'channel' | 'list' | 'mentions' | 'direct' | 'roleTimeline';
|
||||||
name: string | null;
|
name: string | null;
|
||||||
width: number;
|
width: number;
|
||||||
widgets?: ColumnWidget[];
|
widgets?: ColumnWidget[];
|
||||||
|
|
@ -34,7 +34,7 @@ export type Column = {
|
||||||
withRenotes?: boolean;
|
withRenotes?: boolean;
|
||||||
withReplies?: boolean;
|
withReplies?: boolean;
|
||||||
onlyFiles?: boolean;
|
onlyFiles?: boolean;
|
||||||
soundSetting: SoundStore;
|
soundSetting?: SoundStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deckStore = markRaw(new Storage('deck', {
|
export const deckStore = markRaw(new Storage('deck', {
|
||||||
|
|
@ -77,7 +77,7 @@ export const loadDeck = async () => {
|
||||||
key: deckStore.state.profile,
|
key: deckStore.state.profile,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'NO_SUCH_KEY') {
|
if (typeof err === 'object' && err != null && 'code' in err && err.code === 'NO_SUCH_KEY') {
|
||||||
// 後方互換性のため
|
// 後方互換性のため
|
||||||
if (deckStore.state.profile === 'default') {
|
if (deckStore.state.profile === 'default') {
|
||||||
saveDeck();
|
saveDeck();
|
||||||
|
|
@ -159,6 +159,7 @@ export function swapLeftColumn(id: Column['id']) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
saveDeck();
|
saveDeck();
|
||||||
}
|
}
|
||||||
|
|
@ -175,6 +176,7 @@ export function swapRightColumn(id: Column['id']) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
saveDeck();
|
saveDeck();
|
||||||
}
|
}
|
||||||
|
|
@ -195,6 +197,7 @@ export function swapUpColumn(id: Column['id']) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
saveDeck();
|
saveDeck();
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +218,7 @@ export function swapDownColumn(id: Column['id']) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
saveDeck();
|
saveDeck();
|
||||||
}
|
}
|
||||||
|
|
@ -266,6 +270,7 @@ export function removeColumnWidget(id: Column['id'], widget: ColumnWidget) {
|
||||||
const columnIndex = deckStore.state.columns.findIndex(c => c.id === id);
|
const columnIndex = deckStore.state.columns.findIndex(c => c.id === id);
|
||||||
const column = deepClone(deckStore.state.columns[columnIndex]);
|
const column = deepClone(deckStore.state.columns[columnIndex]);
|
||||||
if (column == null) return;
|
if (column == null) return;
|
||||||
|
if (column.widgets == null) column.widgets = [];
|
||||||
column.widgets = column.widgets.filter(w => w.id !== widget.id);
|
column.widgets = column.widgets.filter(w => w.id !== widget.id);
|
||||||
columns[columnIndex] = column;
|
columns[columnIndex] = column;
|
||||||
deckStore.set('columns', columns);
|
deckStore.set('columns', columns);
|
||||||
|
|
@ -288,6 +293,7 @@ export function updateColumnWidget(id: Column['id'], widgetId: string, widgetDat
|
||||||
const columnIndex = deckStore.state.columns.findIndex(c => c.id === id);
|
const columnIndex = deckStore.state.columns.findIndex(c => c.id === id);
|
||||||
const column = deepClone(deckStore.state.columns[columnIndex]);
|
const column = deepClone(deckStore.state.columns[columnIndex]);
|
||||||
if (column == null) return;
|
if (column == null) return;
|
||||||
|
if (column.widgets == null) column.widgets = [];
|
||||||
column.widgets = column.widgets.map(w => w.id === widgetId ? {
|
column.widgets = column.widgets.map(w => w.id === widgetId ? {
|
||||||
...w,
|
...w,
|
||||||
data: widgetData,
|
data: widgetData,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue