Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlights v2 structure #431

Merged
merged 5 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/late-cheetahs-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'mexit': patch
'mexit-webapp': patch
---

Highlight V2 API changes
6 changes: 5 additions & 1 deletion apps/extension/src/Hooks/useHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export const useHighlightAPI = () => {
type: 'HIGHLIGHT',
subType: 'ADD_HIGHLIGHT',
headers: workspaceHeaders(),
body: highlight
body: {
data: {
properties: highlight.properties
}
}
}

const response = await chrome.runtime.sendMessage(request)
Expand Down
8 changes: 5 additions & 3 deletions apps/extension/src/Hooks/useSaveChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export function useSaveChanges() {
const isCapturedHighlight = selection?.range && window.location.href

const highlight = isCapturedHighlight && {
entityId: generateHighlightId(),
properties: {
sourceUrl: selection?.range && deleteQueryParams(window.location.href),
saveableRange: selection?.range,
Expand All @@ -186,7 +185,7 @@ export function useSaveChanges() {
}

try {
await saveHighlight(
const highlightId = await saveHighlight(
{
...highlight,
properties: {
Expand All @@ -196,7 +195,10 @@ export function useSaveChanges() {
},
document.title
)
addHighlightInStore(highlight)
addHighlightInStore({
entityId: highlightId,
...highlight
})
toast('Highlight saved!')
} catch (err) {
console.error(err)
Expand Down
27 changes: 15 additions & 12 deletions apps/webapp/src/Hooks/API/useHighlightAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export const useHighlightAPI = () => {
const saveHighlight = async (h: Highlight) => {
const reqData = {
// workspaceId: getWorkspaceId(),
properties: h.properties,
entityId: h.entityId
data: {
properties: h.properties
}
}
const res = await API.highlight.save(reqData)
mog('We saved that highlight', { res })
Expand All @@ -23,17 +24,19 @@ export const useHighlightAPI = () => {
expiry: GET_REQUEST_MINIMUM_GAP_IN_MS
})
try {
const highlights = res?.Items?.map((item: any) => {
if (item.properties?.content) {
const content = deserializeContent(item.properties.content)
item.properties.content = content
}
const highlights = res
?.map((item: any) => {
if (item.properties?.content) {
const content = deserializeContent(item.properties.content)
item.properties.content = content
}

return {
properties: item?.properties,
entityId: item?.entityId
} as Highlight
}).filter((v: undefined | Highlight) => !!v)
return {
properties: item?.properties,
entityId: item?.entityRefID
} as Highlight
})
.filter((v: undefined | Highlight) => !!v)
return highlights
} catch (e) {
mog('Error fetching highlights', { e })
Expand Down
2 changes: 2 additions & 0 deletions apps/webapp/src/Hooks/useHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const useHighlightSync = () => {
await highlightsAPI
.getAllHighlights()
.then((highlights) => {
console.log('highlights', highlights)
if (highlights) {
mog('SETTING HIGHLIGHTS', { highlights })
setHighlights(highlights)
getEntitiyInitializer('initializeHighlights', highlights)
}
Expand Down
6 changes: 2 additions & 4 deletions apps/webapp/src/Views/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ export const Register = () => {

<InputFormError
name="invite"
label="Invite Code"
label="Invite Code (Optional)"
inputProps={{
placeholder: 'Got an invite? Enter it here!',
...registerForm.register('invite', {
required: true
})
...registerForm.register('invite', {})
}}
errors={regErrors}
></InputFormError>
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/Workers/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ const initializeHighlightsExtension = async () => {
.then((d) => d.json())
.then((d: any) => {
const highlights =
d?.Items?.map((item) => {
d?.map((item) => {
if (item?.properties?.content) {
const content = deserializeContent(item.properties.content)
item.properties.content = content
}

return {
properties: item?.properties,
entityId: item?.entityId
entityId: item?.entityRefID
} as Highlight
}) ?? []

Expand Down
1 change: 1 addition & 0 deletions libs/core/src/Stores/highlight.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const highlightStoreConfig = (set, get) => ({

getHighlightsOfUrl: (url: string) => {
const withoutScrollUrl = deleteQueryParams(url)
mog('GET URL', { url, withoutScrollUrl })

const highlights = get().highlights ?? []

Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/Types/Highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface Highlight {
/**
* ID of the highlight
*/
entityId: string
entityId?: string

/**
* Properties of the highlight
Expand Down