Skip to content

Commit fb071f6

Browse files
authored
Merge pull request #2 from progzone122/master
add contributors store
2 parents b144bc6 + 108515f commit fb071f6

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

src/components/CommunitySection.svelte

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script>
22
import axios from "axios";
3+
import { contributorsStore, updateContributorsStore, checkDataValidity } from '../stores/contributors.js';
4+
import { onMount } from 'svelte';
35
46
export let contributors = [];
57
@@ -17,17 +19,26 @@
1719
};
1820
1921
const updateContributors = async () => {
22+
const updatedContributors = [];
2023
for (let i = 0; i < contributors.length; i++) {
2124
const profile = await getGitHubProfile(contributors[i]);
2225
if (profile) {
23-
contributors[i] = { ...contributors[i], ...profile };
26+
updatedContributors.push({ ...contributors[i], ...profile });
2427
}
2528
}
29+
return updatedContributors;
2630
};
2731
28-
import { onMount } from 'svelte';
29-
onMount(() => {
30-
updateContributors();
32+
onMount(async () => {
33+
const validData = checkDataValidity();
34+
if (validData.contributors.length === 0) {
35+
// If the data is missing or out of date, update it
36+
const updatedContributors = await updateContributors();
37+
updateContributorsStore(updatedContributors);
38+
} else {
39+
contributors = validData.contributors;
40+
updateContributorsStore(validData.contributors);
41+
}
3142
});
3243
</script>
3344

@@ -36,7 +47,7 @@
3647
<p class="text-sm mb-4 text-center lg:text-left">Join our community and contribute to the project</p>
3748

3849
<div class="flex flex-wrap gap-5 justify-center lg:justify-start">
39-
{#each contributors as contributor}
50+
{#each $contributorsStore.contributors as contributor}
4051
<a href="{contributor.url}" target="_blank">
4152
<div class="flex justify-center cursor-pointer select-none transition transform hover:scale-95">
4253
<img src={contributor.avatar} alt={contributor.name} class="cursor-pointer w-16 h-16 object-cover border-2 border-white hover:border-color9" />

src/routes/+page.svelte

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919
}
2020
];
2121
22-
let contributors = [
23-
"progzone122",
24-
"shomykohai",
25-
"GitFASTBOOT",
26-
"R0rt1z2",
27-
"OverWorldD"
28-
];
22+
let contributors = ["progzone122", "shomykohai", "GitFASTBOOT", "R0rt1z2", "OverWorldD"];
2923
</script>
3024

3125
<HeroSection />
@@ -38,8 +32,7 @@
3832
header="Testpoints"
3933
text="Explore testpoints for your device completely free of charge" />
4034
<div id="supported-devices">
41-
<SupportedDevices devices="{devices}" />
35+
<SupportedDevices {devices} />
4236
</div>
43-
<CommunitySection contributors="{contributors}" />
44-
<StickersSection />
45-
<!-- -->
37+
<CommunitySection {contributors} />
38+
<StickersSection />

src/stores/contributors.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { writable } from 'svelte/store';
2+
3+
const isClient = typeof window !== 'undefined';
4+
5+
let storedData = { contributors: [], timestamp: 0 };
6+
7+
// Get data from localStorage, if available
8+
if (isClient) {
9+
const stored = localStorage.getItem('contributors_data');
10+
storedData = stored ? JSON.parse(stored) : { contributors: [], timestamp: 0 };
11+
}
12+
13+
export const contributorsStore = writable(storedData);
14+
15+
export const updateContributorsStore = (newContributors) => {
16+
const currentTime = Date.now();
17+
const updatedData = {
18+
contributors: newContributors,
19+
timestamp: currentTime,
20+
};
21+
contributorsStore.set(updatedData);
22+
if (isClient) {
23+
localStorage.setItem('contributors_data', JSON.stringify(updatedData));
24+
}
25+
};
26+
27+
// Function for checking whether the data is up to date (12 hours)
28+
export const checkDataValidity = () => {
29+
const currentTime = Date.now();
30+
const timeElapsed = currentTime - storedData.timestamp;
31+
if (timeElapsed > 12 * 60 * 60 * 1000) {
32+
return { contributors: [], timestamp: currentTime };
33+
}
34+
return storedData;
35+
};

0 commit comments

Comments
 (0)