Skip to content

Commit

Permalink
Merge pull request #28 from biensupernice/feature/persists-collective
Browse files Browse the repository at this point in the history
Persist Collective
  • Loading branch information
jalvarado91 authored Dec 27, 2023
2 parents 3614c42 + fe208cc commit 1e814e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/client/TracksScreen/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,28 @@ export const useNavbarStore = create<NavbarStore>((set, get) => ({
export type CollectiveSelectStore = {
selected: "all" | "soulection" | "sasha-marie-radio";
setSelected: (collective: "all" | "soulection" | "sasha-marie-radio") => void;
loadPersisted: () => void;
};

export const useCollectiveSelectStore = create<CollectiveSelectStore>(
(set, get) => ({
selected: "soulection",
setSelected(collective) {
console.log(collective);
set({
selected: collective,
});
localStorage.setItem("selectedCollective", collective);
},
loadPersisted: () => {
const persistedCollective = localStorage.getItem("selectedCollective");
if (persistedCollective) {
set({
selected: persistedCollective as
| "all"
| "soulection"
| "sasha-marie-radio",
});
}
},
})
);
Expand Down Expand Up @@ -89,6 +101,7 @@ export default function Navbar({
>
<CollectiveSelect
onValueChange={(v: any) => selectCollective(v)}
value={selectedCollective}
defaultValue={selectedCollective}
>
<CollectiveSelectTrigger className="w-full">
Expand Down
8 changes: 8 additions & 0 deletions src/client/TracksScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function TracksScreen({ searchText }: Props) {

const { data: episodes, error } = useEpisodes();

const loadPersistedCollective = useCollectiveSelectStore(
(s) => s.loadPersisted
);

useEffect(() => {
loadPersistedCollective();
}, []);

const {
currentTrackId,
onTrackClick,
Expand Down

1 comment on commit 1e814e5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for soulector ready!

✅ Preview
https://soulector-nkt3kes59-jalvarado91.vercel.app

Built with commit 1e814e5.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.