Skip to content

Commit 5999786

Browse files
authored
Merge pull request #37 from dapplets/dap-4799
feat: fork of own documents (DAP-4799)
2 parents ad49180 + a059b32 commit 5999786

File tree

5 files changed

+126
-87
lines changed

5 files changed

+126
-87
lines changed

apps/extension/src/contentscript/multitable-panel/components/application-card.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ const CardContent = styled.div`
4242
width: 100%;
4343
`
4444

45-
type TTextLink = {
45+
type TText = {
4646
bold?: boolean
4747
small?: boolean
4848
ellipsis?: boolean
4949
$color?: string
5050
}
5151

52-
const TextLink = styled.div<TTextLink>`
52+
const Text = styled.div<TText>`
5353
display: block;
5454
margin: 0;
5555
font-size: 14px;
@@ -117,7 +117,7 @@ const SideLine = styled.div`
117117
`
118118

119119
const DocumentCardList = styled.div`
120-
width: 100%;
120+
width: calc(100% - 32px);
121121
margin-right: 10px;
122122
display: flex;
123123
flex-direction: column;
@@ -241,16 +241,27 @@ const ApplicationCard: React.FC<IApplicationCard> = ({
241241
</Thumbnail>
242242

243243
<CardContent>
244-
<TextLink $color={textColor} bold ellipsis>
244+
<Text $color={textColor} bold ellipsis>
245245
{metadata.name || appId}
246-
</TextLink>
246+
</Text>
247247

248-
<TextLink small ellipsis>
248+
<Text small ellipsis>
249249
{source === EntitySourceType.Local && (
250-
<Badge margin="0 8px 0 0" text={source} theme={'yellow'} />
250+
<Badge
251+
margin="0 8px 0 0"
252+
text={source}
253+
theme={'yellow'}
254+
style={{ transform: 'translate(0px, -1px)' }}
255+
/>
251256
)}{' '}
252257
{accountId ? `@${accountId}` : null}
253-
</TextLink>
258+
</Text>
259+
260+
{src ? (
261+
<Text small ellipsis title={src}>
262+
{`ID: ${src}`}
263+
</Text>
264+
) : null}
254265
</CardContent>
255266

256267
<ButtonLink

apps/extension/src/contentscript/multitable-panel/components/badge.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,26 @@ export interface IBadgeProps {
5959
size?: keyof typeof SizeMap
6060
icon?: React.JSX.Element
6161
onClick?: React.MouseEventHandler<HTMLSpanElement>
62+
style?: React.CSSProperties
6263
}
6364

64-
export const Badge: FC<IBadgeProps> = ({ text, theme, margin, icon, onClick, size = 'tiny' }) => {
65+
export const Badge: FC<IBadgeProps> = ({
66+
text,
67+
theme,
68+
margin,
69+
icon,
70+
onClick,
71+
size = 'tiny',
72+
style,
73+
}) => {
6574
return (
6675
<Wrapper
6776
$margin={margin}
6877
$theme={theme}
6978
onClick={onClick}
7079
$isClickable={!!onClick}
7180
$size={size}
81+
style={style}
7282
>
7383
{icon ? <span style={{ fontSize: SizeMap[size].iconSize }}>{icon}</span> : null}
7484
<span>{text}</span>

apps/extension/src/contentscript/multitable-panel/components/document-card.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const Card = styled.div`
1010
border-radius: 10px;
1111
background: #f8f9ff;
1212
border: 1px solid #eceef0;
13-
font-family: sans-serif;
1413
&:hover {
1514
background: rgba(24, 121, 206, 0.1);
1615
}
@@ -90,7 +89,7 @@ const CardContent = styled.div`
9089
width: 100%;
9190
`
9291

93-
const TextLink = styled.div<{ bold?: boolean; small?: boolean; ellipsis?: boolean }>`
92+
const Text = styled.div<{ bold?: boolean; small?: boolean; ellipsis?: boolean }>`
9493
display: block;
9594
margin: 0;
9695
font-size: 14px;
@@ -171,16 +170,22 @@ export const DocumentCard: React.FC<Props> = ({
171170
</ThumbnailGroup>
172171

173172
<CardContent>
174-
<TextLink bold ellipsis>
173+
<Text bold ellipsis>
175174
{metadata?.name || (srcParts && srcParts[2]) || 'New Document'}
176-
</TextLink>
175+
</Text>
177176

178-
<TextLink small ellipsis>
177+
<Text small ellipsis>
179178
{source === EntitySourceType.Local && (
180179
<Badge margin="0 8px 0 0" text={source} theme={'yellow'} />
181180
)}{' '}
182181
{srcParts?.[0] && `@${srcParts[0]}`}
183-
</TextLink>
182+
</Text>
183+
184+
{src ? (
185+
<Text small ellipsis title={src}>
186+
{`ID: ${src}`}
187+
</Text>
188+
) : null}
184189
</CardContent>
185190
<ButtonLink className={disabled ? 'disabled' : ''} disabled={disabled} onClick={onChange}>
186191
<CheckedIcon />

libs/backend/src/services/document/document.service.ts

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -114,55 +114,61 @@ export class DocumentSerivce {
114114

115115
const document = await this.documentRepository.constructItem(dto)
116116

117-
if (mutation.authorId === loggedInAccountId) {
118-
// create document remotely, add id to mutation remotely ? (need to be merged)
117+
// ToDo: should mutation be saved locally or remote?
118+
// if (mutation.authorId === loggedInAccountId) {
119+
// // create document remotely, add id to mutation remotely ? (need to be merged)
120+
121+
// // can be null if mutation was locally edited before
122+
// const editingMutation = this._replaceAppInstance(mutation, appId, null, document.id)
123+
124+
// if (!editingMutation) {
125+
// throw new Error('No app in mutation with that ID and empty document')
126+
// }
127+
128+
// const [savedDocument, savedMutation] = await this.unitOfWorkService.runInTransaction((tx) =>
129+
// Promise.all([
130+
// this.documentRepository.createItem(document, tx),
131+
// this.mutationService.editMutation(
132+
// { ...editingMutation, source: EntitySourceType.Origin },
133+
// undefined,
134+
// tx
135+
// ), // ToDo: undefined
136+
// ])
137+
// )
138+
139+
// return {
140+
// document: savedDocument.toDto(),
141+
// mutation: savedMutation,
142+
// }
143+
// } else {
144+
// create document remotely, make mutation local, add id to mutation
145+
146+
const savedDocument = await this.documentRepository.createItem(document)
147+
148+
if (
149+
!mutation.apps.some((app) => app.appId === appId && app.documentId === document.id) ||
150+
mutation.source === EntitySourceType.Origin
151+
) {
152+
// ToDo: navie implementation
153+
mutation.apps = mutation.apps
154+
.filter((app) => !(app.appId === appId && app.documentId === null)) // remove apps without documents
155+
.concat({ appId, documentId: document.id }) // add new document
119156

120-
// can be null if mutation was locally edited before
121-
const editingMutation = this._replaceAppInstance(mutation, appId, null, document.id)
122-
123-
if (!editingMutation) {
124-
throw new Error('No app in mutation with that ID and empty document')
125-
}
126-
127-
const [savedDocument, savedMutation] = await this.unitOfWorkService.runInTransaction((tx) =>
128-
Promise.all([
129-
this.documentRepository.createItem(document, tx),
130-
this.mutationService.editMutation(
131-
{ ...editingMutation, source: EntitySourceType.Origin },
132-
undefined,
133-
tx
134-
), // ToDo: undefined
135-
])
136-
)
157+
const savedMutation = await this.mutationService.saveMutation({
158+
...mutation,
159+
source: EntitySourceType.Local,
160+
})
137161

138162
return {
139163
document: savedDocument.toDto(),
140164
mutation: savedMutation,
141165
}
142-
} else {
143-
// create document remotely, make mutation local, add id to mutation
144-
145-
const savedDocument = await this.documentRepository.createItem(document)
146-
147-
// ToDo: null authorId is possible here
148-
const editingMutation = this._replaceAppInstance(mutation, appId, null, document.id)
149-
150-
if (editingMutation || mutation.source === EntitySourceType.Origin) {
151-
const savedMutation = await this.mutationService.saveMutation({
152-
...(editingMutation ?? mutation),
153-
source: EntitySourceType.Local,
154-
})
155-
156-
return {
157-
document: savedDocument.toDto(),
158-
mutation: savedMutation,
159-
}
160-
}
166+
}
161167

162-
return {
163-
document: savedDocument.toDto(),
164-
}
168+
return {
169+
document: savedDocument.toDto(),
165170
}
171+
// }
166172
}
167173

168174
private async _editLocalDocumentInMutation(

libs/shared-components/src/mini-overlay/index.tsx

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,39 +159,46 @@ interface IMiniOverlayProps extends Partial<IWalletConnect> {
159159
trackingRefs?: Set<React.RefObject<HTMLDivElement>>
160160
}
161161

162-
export const AppSwitcher: FC<IAppSwitcherProps> = ({ app, enableApp, disableApp, isLoading }) => (
163-
<>
164-
{isLoading ? (
165-
<Loading>
166-
<Spinner animation="border" variant="primary"></Spinner>
167-
</Loading>
168-
) : (
169-
<MutationIconWrapper
170-
title={app.localId}
171-
$isStopped={!app.settings.isEnabled}
172-
$isButton={true}
173-
>
174-
{app?.metadata.image ? <Image image={app?.metadata.image} /> : <MutationFallbackIcon />}
162+
export const AppSwitcher: FC<IAppSwitcherProps> = ({ app, enableApp, disableApp, isLoading }) => {
163+
const docMeta = (app as any).documentId?.split('/')
164+
return (
165+
<>
166+
{isLoading ? (
167+
<Loading>
168+
<Spinner animation="border" variant="primary"></Spinner>
169+
</Loading>
170+
) : (
171+
<MutationIconWrapper
172+
title={
173+
(app as any).documentId
174+
? `${app.localId}:\n${docMeta?.[2]}\nby ${docMeta?.[0]}`
175+
: app.localId
176+
}
177+
$isStopped={!app.settings.isEnabled}
178+
$isButton={true}
179+
>
180+
{app?.metadata.image ? <Image image={app?.metadata.image} /> : <MutationFallbackIcon />}
175181

176-
{!app.settings.isEnabled ? (
177-
<LabelAppTop className="labelAppTop">
178-
<StopTopIcon />
179-
</LabelAppTop>
180-
) : null}
182+
{!app.settings.isEnabled ? (
183+
<LabelAppTop className="labelAppTop">
184+
<StopTopIcon />
185+
</LabelAppTop>
186+
) : null}
181187

182-
{app.settings.isEnabled ? (
183-
<LabelAppCenter className="labelAppCenter" onClick={disableApp}>
184-
<StopCenterIcon />
185-
</LabelAppCenter>
186-
) : (
187-
<LabelAppCenter className="labelAppCenter" onClick={enableApp}>
188-
<PlayCenterIcon />
189-
</LabelAppCenter>
190-
)}
191-
</MutationIconWrapper>
192-
)}
193-
</>
194-
)
188+
{app.settings.isEnabled ? (
189+
<LabelAppCenter className="labelAppCenter" onClick={disableApp}>
190+
<StopCenterIcon />
191+
</LabelAppCenter>
192+
) : (
193+
<LabelAppCenter className="labelAppCenter" onClick={enableApp}>
194+
<PlayCenterIcon />
195+
</LabelAppCenter>
196+
)}
197+
</MutationIconWrapper>
198+
)}
199+
</>
200+
)
201+
}
195202

196203
export const MiniOverlay: FC<IMiniOverlayProps> = ({
197204
baseMutation,

0 commit comments

Comments
 (0)