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

chore: fetch personal pp and remove notifications #23

Merged
merged 4 commits into from
Mar 6, 2024
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ open http://localhost:8080
#### Mobile

![screenshot 2](https://github.com/ubiquity/devpool-directory-ui/assets/4975670/b7861ce7-1f1f-49a9-b8e2-ebb20724ee67)

9 changes: 4 additions & 5 deletions src/home/fetch-github/fetch-and-display-previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export async function fetchAndDisplayPreviewsFromCache(sorting?: Sorting, option
tasks: [],
};
}
const cachedTasks = _cachedTasks.tasks.map((task) => ({ ...task, isNew: false, isModified: false })) as TaskMaybeFull[];

const cachedTasks = _cachedTasks.tasks as TaskMaybeFull[];
taskManager.syncTasks(cachedTasks);

if (!cachedTasks.length) {
// load from network if there are no cached issues
return fetchAndDisplayPreviewsFromNetwork(sorting, options);
Expand Down Expand Up @@ -71,8 +73,7 @@ export function verifyGitHubIssueState(cachedTasks: TaskMaybeFull[], fetchedPrev
if (cachedTask) {
if (taskWithFullTest(cachedTask)) {
const cachedFullIssue = cachedTask.full;
const isModified = new Date(cachedFullIssue.updated_at) < new Date(fetched.preview.updated_at);
const task = { ...fetched, full: cachedFullIssue, isNew: false, isModified };
const task = { ...fetched, full: cachedFullIssue };
return task;
} else {
// no full issue in task
Expand All @@ -82,8 +83,6 @@ export function verifyGitHubIssueState(cachedTasks: TaskMaybeFull[], fetchedPrev
}
return {
preview: fetched.preview,
isNew: true,
isModified: false,
} as TaskNoFull;
});
}
Expand Down
16 changes: 16 additions & 0 deletions src/home/fetch-github/fetch-avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,21 @@ export async function fetchAvatar(orgName: string) {
}
} catch (error) {
console.error(`Failed to fetch avatar for organization ${orgName}: ${error}`);
const {
data: { avatar_url: avatarUrl },
} = await octokit.rest.users.getByUsername({ username: orgName });
if (avatarUrl) {
// Fetch the image as a Blob and save it to IndexedDB
const response = await fetch(avatarUrl);
const blob = await response.blob();
await saveImageToCache({
dbName: "GitHubAvatars",
storeName: "ImageStore",
keyName: "name",
orgName: `avatarUrl-${orgName}`,
avatarBlob: blob,
});
organizationImageCache.set(orgName, blob);
}
}
}
13 changes: 1 addition & 12 deletions src/home/getters/get-local-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,5 @@ export function getLocalStore(key: string): TaskStorageItems | OAuthToken | null

export function setLocalStore(key: string, value: TaskStorageItems | OAuthToken) {
// remove state from issues before saving to local storage
if ("tasks" in value && value.tasks.length && "isNew" in value.tasks[0] && "isModified" in value.tasks[0]) {
const tasksWithoutState = value.tasks.map(({ preview, full }) => ({
preview,
full,
}));
localStorage[key] = JSON.stringify({
...value,
tasks: tasksWithoutState,
});
} else {
localStorage[key] = JSON.stringify(value);
}
localStorage[key] = JSON.stringify(value);
}
7 changes: 0 additions & 7 deletions src/home/rendering/render-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ function everyNewIssue({ taskPreview, container }: { taskPreview: TaskMaybeFull;
issueElement.setAttribute("data-preview-id", taskPreview.preview.id.toString());
issueElement.classList.add("issue-element-inner");

if (taskPreview.isNew) {
issueWrapper.classList.add("new-task");
}
if (taskPreview.isModified) {
issueWrapper.classList.add("modified-task");
}

const urlPattern = /https:\/\/github\.com\/([^/]+)\/([^/]+)\//;
const match = taskPreview.preview.body.match(urlPattern);
const organizationName = match?.[1];
Expand Down
20 changes: 3 additions & 17 deletions static/style/inverted-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
display: flex;
align-items: center;
height: 16px;
text-overflow: ellipsis;
overflow: hidden;
display: inline-block;
}
input[type="radio"] {
background-color: unset;
Expand Down Expand Up @@ -318,23 +321,6 @@
.full {
display: unset !important;
}
.new-task,
.modified-task {
position: relative;
}
.new-task::before,
.modified-task::before {
content: "";
display: inline-block;
position: absolute;
height: 100%;
width: 4px;
left: 0;
background-color: #00ffff;
}
.modified-task::before {
background-color: #ffff00;
}
@media screen and (max-width: 804px) {
.mid {
display: none !important;
Expand Down
20 changes: 3 additions & 17 deletions static/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
display: flex;
align-items: center;
height: 16px;
text-overflow: ellipsis;
overflow: hidden;
display: inline-block;
}
input[type="radio"] {
background-color: unset;
Expand Down Expand Up @@ -318,23 +321,6 @@
.full {
display: unset !important;
}
.new-task,
.modified-task {
position: relative;
}
.new-task::before,
.modified-task::before {
content: "";
display: inline-block;
position: absolute;
height: 100%;
width: 4px;
left: 0;
background-color: #0ff;
}
.modified-task::before {
background-color: #ff0;
}
@media screen and (max-width: 804px) {
.mid {
display: none !important;
Expand Down
Loading