Skip to content

Commit

Permalink
refactor: externalize some parts of code
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Mar 26, 2024
1 parent ef3c3bc commit 55a8e74
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 187 deletions.
1 change: 1 addition & 0 deletions app/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
67 changes: 0 additions & 67 deletions app/api/utils/cid.ts

This file was deleted.

34 changes: 0 additions & 34 deletions app/api/utils/tid.ts

This file was deleted.

56 changes: 0 additions & 56 deletions app/api/utils/varint.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { For, createEffect, createMemo, createSignal, lazy } from 'solid-js';

import * as TID from '@mary/atproto-tid';
import {
type InfiniteData,
createInfiniteQuery,
Expand All @@ -11,7 +12,6 @@ import {
import type { AppBskyGraphListitem, Brand, ComAtprotoRepoApplyWrites } from '~/api/atp-schema';
import { multiagent, renderAccountName } from '~/api/globals/agent';
import { renderListPurpose } from '~/api/display';
import { getCurrentTid } from '~/api/utils/tid';
import { getCurrentDate, getRecordId } from '~/api/utils/misc';

import type { ListMembersPage } from '~/api/queries/get-list-members';
Expand Down Expand Up @@ -137,7 +137,7 @@ const AddProfileInListDialog = (props: AddProfileInListDialogProps) => {
creations.push({
$type: 'com.atproto.repo.applyWrites#create',
collection: 'app.bsky.graph.listitem',
rkey: getCurrentTid(),
rkey: TID.now(),
value: record,
});
}
Expand Down
7 changes: 4 additions & 3 deletions app/desktop/components/composer/ComposerPane.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { type JSX, For, Show, batch, createEffect, createMemo, createSignal, untrack, lazy } from 'solid-js';
import { unwrap } from 'solid-js/store';

import { createQuery, useQueryClient } from '@pkg/solid-query';
import { makeEventListener } from '@solid-primitives/event-listener';

import * as TID from '@mary/atproto-tid';
import { createQuery, useQueryClient } from '@pkg/solid-query';

import type {
AppBskyEmbedExternal,
AppBskyFeedPost,
Expand All @@ -15,7 +17,6 @@ import type {
} from '~/api/atp-schema';
import { multiagent } from '~/api/globals/agent';
import { extractAppLink } from '~/api/utils/links';
import { getCurrentTid } from '~/api/utils/tid';
import { formatQueryError, getCollectionId, isDid } from '~/api/utils/misc';

import type { ThreadData } from '~/api/models/threads';
Expand Down Expand Up @@ -366,7 +367,7 @@ const ComposerPane = () => {
date.setMilliseconds(i);

const draft = posts[i];
const rkey = getCurrentTid();
const rkey = TID.now();
const uri = `at://${uid}/app.bsky.feed.post/${rkey}`;

const rt = RESOLVED_RT.get(getPostRt(draft))!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSignal } from 'solid-js';

import { getCurrentTid } from '~/api/utils/tid';
import * as TID from '@mary/atproto-tid';

import { closeModal } from '~/com/globals/modals';

Expand Down Expand Up @@ -45,7 +45,7 @@ const SaveDraftDialog = (props: SaveDraftDialogProps) => {
const shouldClear = clear();

const state = context.state;
const id = getCurrentTid();
const id = TID.now();

const serialized: ComposerDraft = {
id: id,
Expand Down
7 changes: 4 additions & 3 deletions app/desktop/components/composer/utils/cid.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as CID from '@mary/atproto-cid';

import { encodeCbor } from '~/api/utils/cbor';
import { CBOR_CODE, createCID, formatCID } from '~/api/utils/cid';

// Sanity-check by requiring a $type here, this is because the records are
// expected to be encoded with it, even though the PDS accepts record writes
// without the field.
export const serializeRecordCid = async (record: { $type: string }) => {
const bytes = encodeCbor(record);
const cid = await createCID(CBOR_CODE, bytes);
const cid = await CID.create(0x71, bytes);

const serialized = formatCID(cid);
const serialized = CID.format(cid);

return serialized;
};
5 changes: 2 additions & 3 deletions app/desktop/components/settings/AddDeckDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createSignal } from 'solid-js';

import * as TID from '@mary/atproto-tid';
import { navigate } from '@pkg/solid-page-router';

import { preferences } from '../../globals/settings';

import { getCurrentTid } from '~/api/utils/tid';

import { closeModal } from '~/com/globals/modals';
import { model } from '~/utils/input';

Expand All @@ -23,7 +22,7 @@ const AddDeckDialog = () => {
const [emoji, setEmoji] = createSignal('⭐');

const handleSubmit = (ev: SubmitEvent) => {
const tid = getCurrentTid();
const tid = TID.now();

const $name = name();
const $emoji = emoji();
Expand Down
5 changes: 3 additions & 2 deletions app/desktop/components/settings/AddPaneDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type Component, Match, Show, Switch, createSignal } from 'solid-js';

import * as TID from '@mary/atproto-tid';

import type { At } from '~/api/atp-schema';
import { getAccountHandle, multiagent } from '~/api/globals/agent';
import { getCurrentTid } from '~/api/utils/tid';

import { FILTER_ALL } from '~/api/queries/get-notifications';

Expand Down Expand Up @@ -72,7 +73,7 @@ const AddPaneDialog = (props: AddPaneDialogProps) => {
// @ts-expect-error
const pane: PaneConfig = {
...partial,
id: getCurrentTid(),
id: TID.now(),
size: SpecificPaneSize.INHERIT,
title: null,
uid: $user,
Expand Down
6 changes: 3 additions & 3 deletions app/desktop/globals/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as TID from '@mary/atproto-tid';

import { DEFAULT_MODERATION_LABELER } from '~/api/globals/defaults';
import type { LanguagePreferences, TranslationPreferences } from '~/api/types';

import type { ModerationOptions } from '~/api/moderation';

import { getCurrentTid } from '~/api/utils/tid';

import { createReactiveLocalStorage } from '~/utils/storage';

import { type DeckConfig, type PaneConfig, PaneSize, SpecificPaneSize } from './panes';
Expand Down Expand Up @@ -129,7 +129,7 @@ export const addPane = <T extends PaneConfig>(
// @ts-expect-error
const pane: PaneConfig = {
...partial,
id: getCurrentTid(),
id: TID.now(),
size: SpecificPaneSize.INHERIT,
title: null,
};
Expand Down
14 changes: 7 additions & 7 deletions app/desktop/lib/settings/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as TID from '@mary/atproto-tid';

import type { At } from '~/api/atp-schema';
import { getAccountData } from '~/api/globals/agent';

import { getCurrentTid } from '~/api/utils/tid';

import {
type DeckConfig,
PANE_TYPE_HOME,
Expand All @@ -15,7 +15,7 @@ import { FILTER_ALL } from '~/api/queries/get-notifications';

export const createEmptyDeck = (): DeckConfig => {
return {
id: getCurrentTid(),
id: TID.now(),
name: 'Personal',
emoji: '⭐',
panes: [],
Expand All @@ -26,13 +26,13 @@ export const createStarterDeck = (uid: At.DID): DeckConfig => {
const data = getAccountData(uid)!;

return {
id: getCurrentTid(),
id: TID.now(),
name: 'Personal',
emoji: '⭐',
panes: [
{
type: PANE_TYPE_HOME,
id: getCurrentTid(),
id: TID.now(),
uid: uid,
size: SpecificPaneSize.INHERIT,
title: null,
Expand All @@ -42,15 +42,15 @@ export const createStarterDeck = (uid: At.DID): DeckConfig => {
},
{
type: PANE_TYPE_NOTIFICATIONS,
id: getCurrentTid(),
id: TID.now(),
uid: uid,
size: SpecificPaneSize.INHERIT,
title: null,
mask: FILTER_ALL,
},
{
type: PANE_TYPE_PROFILE,
id: getCurrentTid(),
id: TID.now(),
uid: uid,
size: SpecificPaneSize.INHERIT,
title: null,
Expand Down
4 changes: 2 additions & 2 deletions app/desktop/views/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { For, Show, Suspense, batch, lazy } from 'solid-js';
import { offset } from '@floating-ui/dom';
import { DragDropProvider, DragDropSensors, SortableProvider, createSortable } from '@thisbeyond/solid-dnd';

import * as TID from '@mary/atproto-tid';
import { ShowFreeze } from '@pkg/solid-freeze';
import { type RouteComponentProps, location, navigate } from '@pkg/solid-page-router';

import { multiagent } from '~/api/globals/agent';
import { getCurrentTid } from '~/api/utils/tid';

import { openModal } from '~/com/globals/modals';
import { Title } from '~/com/lib/meta';
Expand Down Expand Up @@ -107,7 +107,7 @@ const DashboardLayout = (props: RouteComponentProps) => {

if (!deck) {
decks.push({
id: getCurrentTid(),
id: TID.now(),
name: 'New deck',
emoji: '⭐',
panes: [],
Expand Down
Loading

0 comments on commit 55a8e74

Please sign in to comment.