refactor(frontend): ID生成処理を統一
This commit is contained in:
parent
3bc81522c6
commit
93d17aff6c
|
@ -52,6 +52,7 @@ import type { SuggestionType } from '@/utility/autocomplete.js';
|
|||
import MkButton from '@/components/MkButton.vue';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { Autocomplete } from '@/utility/autocomplete.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: string | number | null;
|
||||
|
@ -87,7 +88,7 @@ const emit = defineEmits<{
|
|||
|
||||
const { modelValue, type, autofocus } = toRefs(props);
|
||||
const v = ref(modelValue.value);
|
||||
const id = Math.random().toString(); // TODO: uuid?
|
||||
const id = genId();
|
||||
const focused = ref(false);
|
||||
const changed = ref(false);
|
||||
const invalid = ref(false);
|
||||
|
|
|
@ -57,6 +57,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref, useTemplateRef } from 'vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const particles = ref<{
|
||||
id: string,
|
||||
|
@ -86,7 +87,7 @@ onMounted(() => {
|
|||
const y = (Math.random() * (height.value - 64));
|
||||
const sizeFactor = Math.random();
|
||||
const particle = {
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
x,
|
||||
y,
|
||||
size: 0.2 + ((sizeFactor / 10) * 3),
|
||||
|
|
|
@ -29,6 +29,7 @@ import { i18n } from '@/i18n.js';
|
|||
import { globalEvents } from '@/events.js';
|
||||
import { $i } from '@/i.js';
|
||||
import MkNote from '@/components/MkNote.vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const props = defineProps<{
|
||||
phase: 'aboutNote' | 'howToReact';
|
||||
|
@ -83,7 +84,7 @@ function doNotification(emoji: string): void {
|
|||
if (!$i || !emoji) return;
|
||||
|
||||
const notification: Misskey.entities.Notification = {
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
createdAt: new Date().toUTCString(),
|
||||
type: 'reaction',
|
||||
reaction: emoji,
|
||||
|
|
|
@ -97,6 +97,7 @@ import { i18n } from '@/i18n.js';
|
|||
import { definePage } from '@/page.js';
|
||||
import MkFolder from '@/components/MkFolder.vue';
|
||||
import MkTextarea from '@/components/MkTextarea.vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const announcementsStatus = ref<'active' | 'archived'>('active');
|
||||
|
||||
|
@ -117,7 +118,7 @@ watch(announcementsStatus, (to) => {
|
|||
|
||||
function add() {
|
||||
announcements.value.unshift({
|
||||
_id: Math.random().toString(36),
|
||||
_id: genId(),
|
||||
id: null,
|
||||
title: 'New announcement',
|
||||
text: '',
|
||||
|
|
|
@ -57,6 +57,7 @@ import { misskeyApi } from '@/utility/misskey-api.js';
|
|||
import { useStream } from '@/stream.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import MkFolder from '@/components/MkFolder.vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const connection = markRaw(useStream().useChannel('queueStats'));
|
||||
|
||||
|
@ -113,7 +114,7 @@ onMounted(() => {
|
|||
connection.on('stats', onStats);
|
||||
connection.on('statsLog', onStatsLog);
|
||||
connection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 200,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -41,6 +41,7 @@ import XChart from './overview.queue.chart.vue';
|
|||
import type { ApQueueDomain } from '@/pages/admin/queue.vue';
|
||||
import number from '@/filters/number.js';
|
||||
import { useStream } from '@/stream.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const connection = markRaw(useStream().useChannel('queueStats'));
|
||||
|
||||
|
@ -92,7 +93,7 @@ onMounted(() => {
|
|||
connection.on('stats', onStats);
|
||||
connection.on('statsLog', onStatsLog);
|
||||
connection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 100,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -84,6 +84,7 @@ import { useStream } from '@/stream.js';
|
|||
import { i18n } from '@/i18n.js';
|
||||
import { definePage } from '@/page.js';
|
||||
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const rootEl = useTemplateRef('rootEl');
|
||||
const serverInfo = ref<Misskey.entities.ServerInfoResponse | null>(null);
|
||||
|
@ -170,7 +171,7 @@ onMounted(async () => {
|
|||
|
||||
nextTick(() => {
|
||||
queueStatsConnection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 100,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -158,6 +158,7 @@ import { userPage } from '@/filters/user.js';
|
|||
import * as sound from '@/utility/sound.js';
|
||||
import * as os from '@/os.js';
|
||||
import { confetti } from '@/utility/confetti.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const $i = ensureSignin();
|
||||
|
||||
|
@ -273,7 +274,7 @@ function putStone(pos: number) {
|
|||
playbackRate: 1,
|
||||
});
|
||||
|
||||
const id = Math.random().toString(36).slice(2);
|
||||
const id = genId();
|
||||
props.connection!.send('putStone', {
|
||||
pos: pos,
|
||||
id,
|
||||
|
|
|
@ -70,11 +70,12 @@ import { definePage } from '@/page.js';
|
|||
import { prefer } from '@/preferences.js';
|
||||
import { PREF_DEF } from '@/preferences/def.js';
|
||||
import { getInitialPrefValue } from '@/preferences/manager.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
|
||||
|
||||
const items = ref(prefer.s.menu.map(x => ({
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
type: x,
|
||||
})));
|
||||
|
||||
|
@ -93,7 +94,7 @@ async function addItem() {
|
|||
});
|
||||
if (canceled) return;
|
||||
items.value = [...items.value, {
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
type: item,
|
||||
}];
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ async function save() {
|
|||
|
||||
function reset() {
|
||||
items.value = getInitialPrefValue('menu').map(x => ({
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
type: x,
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -796,6 +796,7 @@ import { globalEvents } from '@/events.js';
|
|||
import { claimAchievement } from '@/utility/achievements.js';
|
||||
import { instance } from '@/instance.js';
|
||||
import { ensureSignin } from '@/i.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const $i = ensureSignin();
|
||||
|
||||
|
@ -1009,7 +1010,7 @@ let smashTimer: number | null = null;
|
|||
|
||||
function testNotification(): void {
|
||||
const notification: Misskey.entities.Notification = {
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
createdAt: new Date().toUTCString(),
|
||||
isRead: false,
|
||||
type: 'test',
|
||||
|
|
|
@ -171,6 +171,7 @@ import { claimAchievement } from '@/utility/achievements.js';
|
|||
import { store } from '@/store.js';
|
||||
import MkInfo from '@/components/MkInfo.vue';
|
||||
import MkTextarea from '@/components/MkTextarea.vue';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const $i = ensureSignin();
|
||||
|
||||
|
@ -199,12 +200,12 @@ watch(() => profile, () => {
|
|||
deep: true,
|
||||
});
|
||||
|
||||
const fields = ref($i.fields.map(field => ({ id: Math.random().toString(), name: field.name, value: field.value })) ?? []);
|
||||
const fields = ref($i.fields.map(field => ({ id: genId(), name: field.name, value: field.value })) ?? []);
|
||||
const fieldEditMode = ref(false);
|
||||
|
||||
function addField() {
|
||||
fields.value.push({
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
name: '',
|
||||
value: '',
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ import { $i } from '@/i.js';
|
|||
import { instance } from '@/instance.js';
|
||||
import { globalEvents } from '@/events.js';
|
||||
import { getProxiedImageUrl } from '@/utility/media-proxy.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
type UploadReturnType = {
|
||||
filePromise: Promise<Misskey.entities.DriveFile>;
|
||||
|
@ -195,7 +196,7 @@ export function chooseFileFromUrl(): Promise<Misskey.entities.DriveFile> {
|
|||
}).then(({ canceled, result: url }) => {
|
||||
if (canceled) return;
|
||||
|
||||
const marker = Math.random().toString(); // TODO: UUIDとか使う
|
||||
const marker = genId();
|
||||
|
||||
// TODO: no websocketモード対応
|
||||
const connection = useStream().useChannel('main');
|
||||
|
|
|
@ -29,6 +29,7 @@ import MkContainer from '@/components/MkContainer.vue';
|
|||
import { aiScriptReadline, createAiScriptEnv } from '@/aiscript/api.js';
|
||||
import { $i } from '@/i.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const name = 'aiscript';
|
||||
|
||||
|
@ -73,7 +74,7 @@ const run = async () => {
|
|||
in: aiScriptReadline,
|
||||
out: (value) => {
|
||||
logs.value.push({
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
text: value.type === 'str' ? value.value : utils.valToString(value),
|
||||
print: true,
|
||||
});
|
||||
|
@ -81,7 +82,7 @@ const run = async () => {
|
|||
log: (type, params) => {
|
||||
switch (type) {
|
||||
case 'end': logs.value.push({
|
||||
id: Math.random().toString(),
|
||||
id: genId(),
|
||||
text: utils.valToString(params.val, true),
|
||||
print: false,
|
||||
}); break;
|
||||
|
|
|
@ -60,6 +60,7 @@ import kmg from '@/filters/kmg.js';
|
|||
import * as sound from '@/utility/sound.js';
|
||||
import { deepClone } from '@/utility/clone.js';
|
||||
import { prefer } from '@/preferences.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const name = 'jobQueue';
|
||||
|
||||
|
@ -144,7 +145,7 @@ connection.on('stats', onStats);
|
|||
connection.on('statsLog', onStatsLog);
|
||||
|
||||
connection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 1,
|
||||
});
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ onMounted(() => {
|
|||
props.connection.on('stats', onStats);
|
||||
props.connection.on('statsLog', onStatsLog);
|
||||
props.connection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 50,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -52,6 +52,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
import { onMounted, onBeforeUnmount, ref } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import bytes from '@/filters/bytes.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
|
||||
const props = defineProps<{
|
||||
connection: Misskey.ChannelConnection<Misskey.Channels['serverStats']>,
|
||||
|
@ -76,7 +77,7 @@ onMounted(() => {
|
|||
props.connection.on('stats', onStats);
|
||||
props.connection.on('statsLog', onStatsLog);
|
||||
props.connection.send('requestLog', {
|
||||
id: Math.random().toString().substring(2, 10),
|
||||
id: genId(),
|
||||
length: 50,
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue