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

1.4.0 #36

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_VERSION=1.2.2
REACT_APP_VERSION=1.4.0
8 changes: 4 additions & 4 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_TEAM = LS6BR8Q859;
INFOPLIST_FILE = App/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = LinkThing;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.4.0;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = com.moscardino.LinkThing;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -371,13 +371,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_TEAM = LS6BR8Q859;
INFOPLIST_FILE = App/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = LinkThing;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.moscardino.LinkThing;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
11 changes: 11 additions & 0 deletions ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@
</array>
<key>ITSAppUsesNonExemptEncryption</key>
<false />
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.getcapacitor.capacitor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>linkthing</string>
</array>
</dict>
</array>
</dict>
</plist>
4 changes: 2 additions & 2 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- Capacitor (5.0.3):
- CapacitorCordova
- CapacitorApp (5.0.2):
- CapacitorApp (5.0.6):
- Capacitor
- CapacitorBrowser (5.0.2):
- Capacitor
Expand Down Expand Up @@ -55,7 +55,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Capacitor: 304a960e431f9e6f78556554ca71c41c1b2b9680
CapacitorApp: 28fef1fd75b2b3686e875216806fb8416d421097
CapacitorApp: 024e1b1bea5f883d79f6330d309bc441c88ad04a
CapacitorBrowser: 7986ee35377383fc40f7c1a0a793e0d9a49fe527
CapacitorClipboard: a198f34cd0ed4d1777da5edae13445227ec05be3
CapacitorCordova: def732a63679698df6fb392bbe6d269a0b61e937
Expand Down
35 changes: 26 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "link-thing",
"version": "1.2.2",
"version": "1.4.0",
"private": true,
"dependencies": {
"@capacitor/app": "^5.0.0",
"@capacitor-community/app-react": "^0.1.0",
"@capacitor/app": "^5.0.6",
"@capacitor/browser": "^5.0.0",
"@capacitor/clipboard": "^5.0.0",
"@capacitor/core": "^5.0.0",
Expand Down Expand Up @@ -62,4 +63,4 @@
"@capacitor/cli": "^5.0.0",
"local-cors-proxy": "^1.1.0"
}
}
}
123 changes: 74 additions & 49 deletions src/api/linkdigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@ import BookmarkResult from "./types/bookmarkResult";

const PAGE_SIZE = 10;

const getBookmarks = async (query?: string, page: number = 0): Promise<BookmarkResult> => {
const settings = await getSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
/**
* Gets the linkding instance URL and token from the settings.
* @returns The linkding instance URL and token from the settings.
*/
const getLinkdingSettings = async (): Promise<{ instanceUrl?: string, token?: string }> => {
const { instanceUrl, token } = await getSettings();

if (instanceUrl === undefined || token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');

return { instanceUrl, token };
};

/**
* Gets the bookmarks from the linkding instance.
* @param query The query to search for.
* @param page The page to load (0 indexed)
* @returns The bookmarks from the linkding instance.
*/
const getBookmarks = async (query?: string, page: number = 0): Promise<BookmarkResult> => {
const { instanceUrl, token } = await getLinkdingSettings();

// Add a delay to debug loading states
// await new Promise<void>(resolve => setTimeout(() => resolve(), 2000));

const url = new URL('api/bookmarks/', settings.instanceUrl);
const url = new URL('api/bookmarks/', instanceUrl);
const params = {} as any;

if (query)
Expand All @@ -28,7 +44,7 @@ const getBookmarks = async (query?: string, page: number = 0): Promise<BookmarkR
url: url.toString(),
params: params,
headers: {
'Authorization': `Token ${settings.token}`
'Authorization': `Token ${token}`
}
});

Expand All @@ -42,18 +58,20 @@ const getBookmarks = async (query?: string, page: number = 0): Promise<BookmarkR
};
};

/**
* Gets a bookmark from the linkding instance.
* @param id The id of the bookmark to get.
* @returns The bookmark from the linkding instance.
*/
const getBookmark = async (id: number): Promise<Bookmark> => {
const settings = await getSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');
const { instanceUrl, token } = await getLinkdingSettings();

const url = new URL(`api/bookmarks/${id}/`, settings.instanceUrl);
const url = new URL(`api/bookmarks/${id}/`, instanceUrl);

const response = await CapacitorHttp.get({
url: url.toString(),
headers: {
'Authorization': `Token ${settings.token}`
'Authorization': `Token ${token}`
}
});

Expand All @@ -63,21 +81,23 @@ const getBookmark = async (id: number): Promise<Bookmark> => {
return response.data as Bookmark;
};

/**
* Gets information about a URL (title, description, etc.)
* @param urlToCheck The URL to check.
* @returns Information about a URL (title, description, etc.)
*/
const checkUrl = async (urlToCheck: string): Promise<BookmarkCheckResult> => {
const settings = await getSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');
const { instanceUrl, token } = await getLinkdingSettings();

const url = new URL(`api/bookmarks/check/`, settings.instanceUrl);
const url = new URL(`api/bookmarks/check/`, instanceUrl);

const response = await CapacitorHttp.get({
url: url.toString(),
params: {
url: urlToCheck
},
headers: {
'Authorization': `Token ${settings.token}`
'Authorization': `Token ${token}`
}
});

Expand All @@ -87,13 +107,14 @@ const checkUrl = async (urlToCheck: string): Promise<BookmarkCheckResult> => {
return response.data as BookmarkCheckResult;
};

/**
* Creates a bookmark in the linkding instance.
* @param bookmark The bookmark to create.
*/
const createBookmark = async (bookmark: Bookmark): Promise<void> => {
const settings = await getSettings();
const { instanceUrl, token } = await getLinkdingSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');

const url = new URL(`api/bookmarks/`, settings.instanceUrl);
const url = new URL(`api/bookmarks/`, instanceUrl);

await CapacitorHttp.post({
url: url.toString(),
Expand All @@ -105,19 +126,20 @@ const createBookmark = async (bookmark: Bookmark): Promise<void> => {
tag_names: bookmark.tag_names
},
headers: {
'Authorization': `Token ${settings.token}`,
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
}
});
};

/**
* Updates a bookmark in the linkding instance.
* @param bookmark The bookmark to update.
*/
const updateBookmark = async (bookmark: Bookmark): Promise<void> => {
const settings = await getSettings();
const { instanceUrl, token } = await getLinkdingSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');

const url = new URL(`api/bookmarks/${bookmark.id}/`, settings.instanceUrl);
const url = new URL(`api/bookmarks/${bookmark.id}/`, instanceUrl);

await CapacitorHttp.patch({
url: url.toString(),
Expand All @@ -128,63 +150,66 @@ const updateBookmark = async (bookmark: Bookmark): Promise<void> => {
tag_names: bookmark.tag_names
},
headers: {
'Authorization': `Token ${settings.token}`,
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
}
});
};

/**
* Performs a patch update to toggle the unread field of a bookmark.
* @param id The id of the bookmark to update.
*/
const updateBookmarkRead = async (id: number): Promise<void> => {
const settings = await getSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');
const { instanceUrl, token } = await getLinkdingSettings();

const bookmark = await getBookmark(id);
const url = new URL(`api/bookmarks/${id}/`, settings.instanceUrl);
const url = new URL(`api/bookmarks/${id}/`, instanceUrl);

await CapacitorHttp.patch({
url: url.toString(),
data: { unread: !bookmark.unread },
headers: {
'Authorization': `Token ${settings.token}`,
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
}
});
};

/**
* Deletes a bookmark from the linkding instance.
* @param id The id of the bookmark to delete.
*/
const deleteBookmark = async (id: number): Promise<void> => {
const settings = await getSettings();
const { instanceUrl, token } = await getLinkdingSettings();

const url = new URL(`api/bookmarks/${id}/`, instanceUrl);

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');

const url = new URL(`api/bookmarks/${id}/`, settings.instanceUrl);

await CapacitorHttp.delete({
url: url.toString(),
headers: {
'Authorization': `Token ${settings.token}`,
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
}
});
};

/**
* Gets the tags from the linkding instance.
* @returns The tags from the linkding instance.
*/
const getTags = async (): Promise<string[]> => {
const settings = await getSettings();

if (settings.instanceUrl === undefined || settings.token === undefined)
throw new Error('Missing Linkdig settings. Please provide them from the Settings page.');
const { instanceUrl, token } = await getLinkdingSettings();

const url = new URL(`api/tags/`, settings.instanceUrl);
const url = new URL(`api/tags/`, instanceUrl);

const response = await CapacitorHttp.get({
url: url.toString(),
params: {
limit: '1000'
},
headers: {
'Authorization': `Token ${settings.token}`
'Authorization': `Token ${token}`
}
});

Expand Down
Loading