@@ -85,5 +85,51 @@ document.addEventListener("DOMContentLoaded", function() {
8585 }
8686
8787 // Set up the Slack channel button event listeners
88- setupSlackChannelButtons ( ) ;
88+ setupSlackChannelButtons ( ) ;
89+
90+ // Function to get the saved Slack channel URL from localStorage and update the button
91+ function loadSlackChannelButton ( ) {
92+ const savedSlackUrl = localStorage . getItem ( 'selectedSlackChannel' ) ;
93+ const savedCommunityName = localStorage . getItem ( 'selectedCommunityName' ) ;
94+
95+ const slackButton = document . querySelector ( '.slack-channel-link' ) ;
96+
97+ if ( savedSlackUrl && slackButton ) {
98+ // Update the button with the saved Slack URL
99+ slackButton . href = savedSlackUrl ;
100+
101+ // Update the title attribute if we have the community name
102+ if ( savedCommunityName ) {
103+ slackButton . title = `${ savedCommunityName } Slack channel` ;
104+ }
105+
106+ // Add click event to clear localStorage after successful redirect
107+ slackButton . addEventListener ( 'click' , function ( ) {
108+ // Clear the stored values after user clicks to join
109+ localStorage . removeItem ( 'selectedSlackChannel' ) ;
110+ localStorage . removeItem ( 'selectedCommunityName' ) ;
111+ } ) ;
112+ } else {
113+ // If no URL was saved, redirect back to communities page or show error
114+ console . error ( 'No Slack channel URL found in localStorage' ) ;
115+
116+ // Option 1: Redirect back to communities page
117+ // window.location.href = '/communities-of-practice';
118+
119+ // Option 2: Update button to show error state
120+ if ( slackButton ) {
121+ slackButton . href = '/communities-of-practice' ;
122+ slackButton . innerHTML = `
123+ <svg version="1.1" viewBox="0 0 90 90" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
124+ <path d="..." fill="currentColor"/>
125+ </svg>
126+ Return to Communities
127+ ` ;
128+ slackButton . title = 'Return to Communities of Practice page' ;
129+ }
130+ }
131+ }
132+
133+ // Load the Slack channel button when page loads
134+ loadSlackChannelButton ( ) ;
89135} ) ;
0 commit comments